Method: String#truncate
- Defined in:
- lib/extra/string.rb
#truncate(length, ending = '') ⇒ Object
Truncate a string to a certain length, and optionally append ending characters to it.
Example: 'foobarbaz'.truncate(3, '...') #=> "foo..."
Returns: String
119 120 121 122 123 124 125 |
# File 'lib/extra/string.rb', line 119 def truncate(length, ending = '') if size > length self[0...length] + ending else self end end |