Sha256: 89c49a0f1a0c0051db93dc5db9b41e7726a2beff2208c5c72b05ecbd55c20271
Contents?: true
Size: 580 Bytes
Versions: 5
Compression:
Stored size: 580 Bytes
Contents
# Extend the string core class to add the truncate method from Rails class String def truncate(truncate_at, options = {}) return dup unless length > truncate_at options[:omission] ||= '...' length_with_room_for_omission = truncate_at - options[:omission].length stop = if options[:separator] rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission else length_with_room_for_omission end "#{self[0...stop]}#{options[:omission]}" end end
Version data entries
5 entries across 5 versions & 1 rubygems