src code

instance method String#truncate

String#truncate([length = 30[, suffix = '...']]) → String

Truncates a string to given length and appends suffix to it (indicating that it is only an excerpt).

Examples
'A random sentence whose length exceeds 30 characters.'.truncate();
// -> 'A random sentence whose len...'
 'Some random text'.truncate();
// -> 'Some random text.'
 'Some random text'.truncate(10);
// -> 'Some ra...'
 'Some random text'.truncate(10, ' [...]');
// -> 'Some [...]'