Method: String#truncate
- Defined in:
- lib/truncate.rb
#truncate(length = 20, omis = "...") ⇒ Object
The main “truncate” class can be passed a length (in number of characters) and / or a custom omission. The default length is 20 characters and the default omission is “…”.
12 13 14 15 16 17 18 |
# File 'lib/truncate.rb', line 12 def truncate(length = 20, omis = "...") text = self.dup if text.length > length text = text[0...length].strip + omis end text end |