Created
July 6, 2016 09:25
-
-
Save Ji-Yuhang/0fec1cd1f491c8b51e8f0d2e395122a8 to your computer and use it in GitHub Desktop.
ruby colorize string
This file contains hidden or 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 | |
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