The following code works:
class String
def color(code)
"\e[#{code}m#{self}\e[0m"
end
end
puts "Anything".color(93)
I want to be able to do:
puts "Anything".red
by catching the red
as a string, and then giving it to a case-block as follows:
class String
case **?WHAT?**
when "red" then color(91)
else color(0)
end
end
but it doesn't work. Is there a smart way to do this? How can I get the method name and use it in a case block?