Class: String

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

Overview

Redefine String class to allow for colorizing, rsplit, and word wrap

Instance Method Summary collapse

Instance Method Details

#blackObject



3
4
5
# File 'lib/string.rb', line 3

def black
    return colorize(30)
end

#blueObject



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

#cyanObject



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

def cyan
    return colorize(36)
end

#greenObject



19
20
21
# File 'lib/string.rb', line 19

def green
    return colorize(32)
end

#purpleObject



23
24
25
# File 'lib/string.rb', line 23

def purple
    return colorize(35)
end

#redObject



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

#whiteObject



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

#yellowObject



45
46
47
# File 'lib/string.rb', line 45

def yellow
    return colorize(33)
end