Created
February 21, 2013 08:07
-
-
Save oscarrenalias/5003090 to your computer and use it in GitHub Desktop.
Easily colorize console output in Ruby:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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