Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/truncate.rb
Instance Method Summary collapse
Instance Method Details
#truncate(length = 20, omis = "...") ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/truncate.rb', line 3 def truncate(length = 20, omis = "...") text = self.dup if text.length > length text = text[0...length].strip + omis end text end |
#words(length = 5, omis = "...") ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/truncate.rb', line 11 def words(length = 5, omis = "...") text = self.dup array = text.split(" ") if array.length > length text = array[0...length].join(" ") + omis end text end |