Module: Aurb::CoreExt::String

Defined in:
lib/aurb/core_ext/string.rb

Constant Summary collapse

COLORS =

Available colors for String#colorize.

[:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white]

Instance Method Summary collapse

Instance Method Details

#colorize(effect) ⇒ Object

Colors a string with color.

"Hello".colorize(:blue)


13
14
15
16
17
18
19
20
21
# File 'lib/aurb/core_ext/string.rb', line 13

def colorize(effect)
  if STDOUT.tty? && ENV['TERM']
    "\033[0;#{30+COLORS.index(effect.to_sym)}m#{self}\033[0m"
  else
    self
  end
rescue
  self
end