Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string.rb
Overview
Modify String class to allow for rsplit and word wrap
Instance Method Summary collapse
Instance Method Details
#fix ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/string.rb', line 3 def fix # Fix unicode (I think???) # Apparently sometimes length and bytesize don't always agree. # When this happens, there are "invisible" bytes, which I need # to be "visible". Converting to hex and back fixes this. if (length != bytesize) return self.unpack("H*").pack("H*") end return self end |
#rsplit(pattern) ⇒ Object
14 15 16 17 18 |
# File 'lib/string.rb', line 14 def rsplit(pattern) ret = rpartition(pattern) ret.delete_at(1) return ret end |
#word_wrap(width = 80) ⇒ Object
20 21 22 |
# File 'lib/string.rb', line 20 def word_wrap(width = 80) return scan(/\S.{0,#{width}}\S(?=\s|$)|\S+/).join("\n") end |