Class: String

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

Constant Summary collapse

ColorMap =
{:default => 39, :cyan => 36, :red => 31, :green => 32, :blue => 34, :magent => 35, :yellow => 33, :white => 37}
Colors =
ColorMap.keys

Instance Method Summary collapse

Instance Method Details

#colorize(color_code) ⇒ Object

colorization



6
7
8
# File 'lib/extensions/string.rb', line 6

def colorize(color_code)
  empty? ?  self :  "\e[#{color_code}m#{self}\e[0m"
end

#random_colorObject



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

def random_color
  self.send(Colors[rand(Colors.length)])
end

#slow_puts(opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/extensions/string.rb', line 20

def slow_puts(opts = {})
  opts[:delay] = 0.02 unless opts[:delay]
  opts[:newline] = true if opts[:newline].nil?
  self.each_char do |x|
    print x
    STDOUT.flush
    sleep opts[:delay]
  end
  puts if opts[:newline]
end