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
- #green ⇒ Object
- #red ⇒ Object
- #white ⇒ Object
- #word_wrap(width = 70) ⇒ 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 |
#green ⇒ Object
11 12 13 |
# File 'lib/string.rb', line 11 def green return colorize(32) end |
#red ⇒ Object
15 16 17 |
# File 'lib/string.rb', line 15 def red return colorize(31) end |
#white ⇒ Object
19 20 21 |
# File 'lib/string.rb', line 19 def white return colorize(37) end |
#word_wrap(width = 70) ⇒ Object
23 24 25 |
# File 'lib/string.rb', line 23 def word_wrap(width = 70) return scan(/\S.{0,#{width}}\S(?=\s|$)|\S+/).join("\n") end |