Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string.rb

Overview

Redefine String class to allow for colorizing and rsplit

Instance Method Summary collapse

Instance Method Details

#blueObject



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

#greenObject



11
12
13
# File 'lib/string.rb', line 11

def green
    return colorize(32)
end

#redObject



15
16
17
# File 'lib/string.rb', line 15

def red
    return colorize(31)
end

#whiteObject



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