how can I print the string in different color?

A

Arul hari

Hai Friends,
How can I print the string in different color in Ruby.
For example,we can take c program,I c program we are having the printing
foramts with lot of colors.


by
vellingiri
 
S

Stephane Wirtel

Arul hari a écrit :
Hai Friends,
How can I print the string in different color in Ruby.
For example,we can take c program,I c program we are having the printing
foramts with lot of colors.


by
vellingiri
gem install colorize
 
A

Ari Brown

Does the word "color" looked very strange to anyone else?

Hai Friends,
How can I print the string in different color in Ruby.
For example,we can take c program,I c program we are having the
printing
foramts with lot of colors.

Check out the HighLine library for that!

Example:

say("This should be <%= color('red', :red) %>!")

notice the hacky use of erb in the string. Sly move there, JEG & Greg!

Also, once you install it, you can try a cool little hack I have (in
honor of me not doing my chemistry homework):
module Kernel
def color(string, color)
return HighLine.new.color(string, color)
end
end

say color("hooray! red!", :red)

that way you don't have to use erb.


~ Ari
English is like a pseudo-random number generator - there are a
bajillion rules to it, but nobody cares.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top