rails/rails — pull request #16190 by oss92 (2014-07-16 14:49:26+00:00)
Title: Word truncation

Patched the truncate strings method to include truncation by word

Examples:

'Once upon a time'.truncate(4, word: true)
=> "Once upon a time"

'Once upon a time in a world far far away'.truncate(4, word: true)
=> "Once upon a time..."

'Once
upon
a
time
in
a
world'.truncate(5, word: true, separator: '
')
=> "Once
upon
a
time
in..."

'Once
upon
a
time
in
a
world'.truncate(5, word: true, separator: '
', omission: '[...]')
=> "Once
upon
a
time
in[...]"