Converting RGB colors to Hexadecimal with ruby Wednesday, 27 August, 2014 by Juan Lebrijo about ruby Just a tip to convert RGB colors to Hexadecimal: def rgb(r, g, b) "##{to_hex r}#{to_hex g}#{to_hex b}" end def to_hex(n) n.to_s(16).rjust(2, '0').upcase end def rgb(r, g, b) "##{to_hex r}#{to_hex g}#{to_hex b}" end def to_hex(n) n.to_s(16).rjust(2, '0').upcase end In console: rgb(50, 205, 50) => "#32CD32"rgb(50, 205, 50) => "#32CD32"