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

#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

#rsplit(pattern) ⇒ Object



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

def rsplit(pattern)
    ret = rpartition(pattern)
    ret.delete_at(1)
    return ret
end

#whiteObject



25
26
27
# File 'lib/string.rb', line 25

def white
    return colorize(37)
end

#word_wrap(width = 70) ⇒ Object



29
30
31
# File 'lib/string.rb', line 29

def word_wrap(width = 70)
    return scan(/\S.{0,#{width}}\S(?=\s|$)|\S+/).join("\n")
end