Skip to content

Instantly share code, notes, and snippets.

@sr
Forked from sunny/string.colorize.rb
Created August 18, 2008 21:31
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 sr/6107 to your computer and use it in GitHub Desktop.
Save sr/6107 to your computer and use it in GitHub Desktop.
class String
# ANSI-colored version of the string
def colorize(color)
n = case color
when :black: 30
when :red: 31
when :green: 32
when :yellow: 33
when :blue: 34
when :magenta: 35
when :cyan: 36
when :white: 37
else raise ArgumentError, "Unknown color `#{color}'"
end
"\033[#{n}m#{self}\033[0m"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment