Gdk::Color to HTML Format Hex

I’m trying to convert the hex code that Gdk::Color.to_s() returns into
HTML Format Hex. I think what needs to be done is some math on the
string, but I’m fairly new to ruby and not sure how to do this. For
instance, if the color in HTML hex is a six string code, #ffffff, then
Gdk::Color would return #ffffffffffff.

Here is an example of how to do it in C, but I’m not sure how to
translate that to ruby.

Thanks in advance.

str = (color.red >> 8).to_s(16)
str += (color.green >> 8).to_s(16)
str += (color.blue >> 8).to_s(16)

Scrap that: “#%02x%02x%02x” % [c.red, c.green, c.blue]

From: [email protected]
To: [email protected]
Date: Tue, 11 Aug 2009 19:55:39 +0100
Subject: Re: [ruby-gnome2-devel-en] Gdk::Color to HTML Format Hex

str = (color.red >> 8).to_s(16)
str += (color.green >> 8).to_s(16)
str += (color.blue >> 8).to_s(16)

Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what’s new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july


ruby-gnome2-devel-en mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en

Internet Explorer 8 - accelerate your Hotmail. Download Internet
Explorer 8


Upgrade to Internet Explorer 8 Optimised for MSN.

http://extras.uk.msn.com/internet-explorer-8/?ocid=T010MSN07A0716U

Damnit, I’m having a real idiot day today …

Scrap that: “#%02x%02x%02x” % [c.red, c.green, c.blue].map {|i| i >> 8}

From: [email protected]
To: [email protected]
Date: Tue, 11 Aug 2009 19:58:33 +0100
Subject: Re: [ruby-gnome2-devel-en] Gdk::Color to HTML Format Hex

Scrap that: “#%02x%02x%02x” % [c.red, c.green, c.blue]

From: [email protected]
To: [email protected]
Date: Tue, 11 Aug 2009 19:55:39 +0100
Subject: Re: [ruby-gnome2-devel-en] Gdk::Color to HTML Format Hex

str = (color.red >> 8).to_s(16)
str += (color.green >> 8).to_s(16)
str += (color.blue >> 8).to_s(16)

Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what’s new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july


ruby-gnome2-devel-en mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en

Internet Explorer 8 - accelerate your Hotmail. Download Internet
Explorer 8
Celebrate a decade of Messenger with free winks, emoticons, display
pics, and more. Get Them Now


Upgrade to Internet Explorer 8 Optimised for MSN.

http://extras.uk.msn.com/internet-explorer-8/?ocid=T010MSN07A0716U

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs