Skip to content

Instantly share code, notes, and snippets.

@oscarrenalias
Created February 21, 2013 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oscarrenalias/5003090 to your computer and use it in GitHub Desktop.
Save oscarrenalias/5003090 to your computer and use it in GitHub Desktop.
Easily colorize console output in Ruby:
class String
# colorization
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
colorize(31)
end
def green
colorize(32)
end
def yellow
colorize(33)
end
def pink
colorize(35)
end
end
#
# How to use
#
puts "This is red".red
puts "This is green".green
puts "This is yellow".yellow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment