# How can I print the string in different color?

**URL:** <https://www.ruby-forum.com/t/how-can-i-print-the-string-in-different-color/118010>\
**Category:** Ruby\
**Created:** [October 23, 2007, 10:49am UTC](https://www.ruby-forum.com/t/how-can-i-print-the-string-in-different-color/118010 "2007-10-23T10:49:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [October 23, 2007, 10:49am UTC](https://www.ruby-forum.com/t/how-can-i-print-the-string-in-different-color/118010/1 "2007-10-23T10:49:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [October 23, 2007, 12:10pm UTC](https://www.ruby-forum.com/t/how-can-i-print-the-string-in-different-color/118010/2 "2007-10-23T12:10:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [October 24, 2007, 2:04am UTC](https://www.ruby-forum.com/t/how-can-i-print-the-string-in-different-color/118010/3 "2007-10-24T02:04:44Z")

</div>

Does the word “color” looked very strange to anyone else?

On Oct 23, 2007, at 4:49 AM, Arul hari wrote:

> 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.
