Skip to content

Instantly share code, notes, and snippets.

@pujiaxun
Created June 14, 2016 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pujiaxun/18c473722ab3810501077b0714d456fc to your computer and use it in GitHub Desktop.
Save pujiaxun/18c473722ab3810501077b0714d456fc to your computer and use it in GitHub Desktop.
A simple patch for String to colorize the output in the terminal.
class String
def black; "\e[30m#{self}\e[0m" end
def red; "\e[31m#{self}\e[0m" end
def green; "\e[32m#{self}\e[0m" end
def brown; "\e[33m#{self}\e[0m" end
def blue; "\e[34m#{self}\e[0m" end
def magenta; "\e[35m#{self}\e[0m" end
def cyan; "\e[36m#{self}\e[0m" end
def gray; "\e[37m#{self}\e[0m" end
end
# puts "This is green".green
# puts "Blue is here".blue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment