Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string.rb
Instance Method Summary collapse
Instance Method Details
#truncate(truncate_at, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/string.rb', line 4 def truncate(truncate_at, = {}) return dup unless length > truncate_at [:omission] ||= '...' length_with_room_for_omission = truncate_at - [:omission].length stop = if [:separator] rindex([:separator], length_with_room_for_omission) || length_with_room_for_omission else length_with_room_for_omission end "#{self[0...stop]}#{[:omission]}" end |