Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string.rb
Overview
Redefine String class to allow for colorizing and rsplit
Instance Method Summary collapse
- #blue ⇒ Object
- #colorize(color) ⇒ Object
- #fix ⇒ Object
- #green ⇒ Object
- #red ⇒ Object
- #rsplit(pattern) ⇒ Object
- #white ⇒ Object
Instance Method Details
#blue ⇒ Object
3 4 5 |
# File 'lib/string.rb', line 3 def blue return colorize(36) end |
#colorize(color) ⇒ Object
7 8 9 |
# File 'lib/string.rb', line 7 def colorize(color) return "\e[#{color}m#{self}\e[0m" end |
#fix ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/string.rb', line 11 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 |
#green ⇒ Object
22 23 24 |
# File 'lib/string.rb', line 22 def green return colorize(32) end |
#red ⇒ Object
26 27 28 |
# File 'lib/string.rb', line 26 def red return colorize(31) end |
#rsplit(pattern) ⇒ Object
30 31 32 33 34 |
# File 'lib/string.rb', line 30 def rsplit(pattern) ret = rpartition(pattern) ret.delete_at(1) return ret end |
#white ⇒ Object
36 37 38 |
# File 'lib/string.rb', line 36 def white return colorize(37) end |