Skip to content

Instantly share code, notes, and snippets.

@Ji-Yuhang
Created July 6, 2016 09:25
Show Gist options
  • Save Ji-Yuhang/0fec1cd1f491c8b51e8f0d2e395122a8 to your computer and use it in GitHub Desktop.
Save Ji-Yuhang/0fec1cd1f491c8b51e8f0d2e395122a8 to your computer and use it in GitHub Desktop.
ruby colorize string
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 "My color is green".green
puts "My color is blue.".blue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment