Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string.rb
Overview
Redefine String class to allow for colorizing, rsplit, and word wrap
Instance Method Summary collapse
- #black ⇒ Object
- #blue ⇒ Object
- #colorize(color) ⇒ Object
- #cyan ⇒ Object
- #green ⇒ Object
- #purple ⇒ Object
- #red ⇒ Object
- #rsplit(pattern) ⇒ Object
- #white ⇒ Object
- #word_wrap(width = 70) ⇒ Object
- #yellow ⇒ Object
Instance Method Details
#black ⇒ Object
3 4 5 |
# File 'lib/string.rb', line 3 def black return colorize(30) end |
#blue ⇒ Object
7 8 9 |
# File 'lib/string.rb', line 7 def blue return colorize(34) end |
#colorize(color) ⇒ Object
11 12 13 |
# File 'lib/string.rb', line 11 def colorize(color) return "\e[#{color}m#{self}\e[0m" end |
#cyan ⇒ Object
15 16 17 |
# File 'lib/string.rb', line 15 def cyan return colorize(36) end |
#green ⇒ Object
19 20 21 |
# File 'lib/string.rb', line 19 def green return colorize(32) end |
#purple ⇒ Object
23 24 25 |
# File 'lib/string.rb', line 23 def purple return colorize(35) end |
#red ⇒ Object
27 28 29 |
# File 'lib/string.rb', line 27 def red return colorize(31) end |
#rsplit(pattern) ⇒ Object
31 32 33 34 35 |
# File 'lib/string.rb', line 31 def rsplit(pattern) ret = rpartition(pattern) ret.delete_at(1) return ret end |
#white ⇒ Object
37 38 39 |
# File 'lib/string.rb', line 37 def white return colorize(37) end |
#word_wrap(width = 70) ⇒ Object
41 42 43 |
# File 'lib/string.rb', line 41 def word_wrap(width = 70) return scan(/\S.{0,#{width}}\S(?=\s|$)|\S+/).join("\n") end |
#yellow ⇒ Object
45 46 47 |
# File 'lib/string.rb', line 45 def yellow return colorize(33) end |