Color Converter for Ruby

Free online color converter with Ruby code examples

Working with color converter in Ruby? Our free online color converter helps Ruby developers format, validate, and process data instantly. Below you will find Ruby code examples using color so you can achieve the same result programmatically in your own projects.

Try the Color Converter Online

Use our free Color Converter directly in your browser — no setup required.

Open Color Converter

Ruby Code Example

require 'color'

# HEX to RGB
hex = Color::RGB.by_hex('#3498db')
puts "RGB: (#{hex.red.to_i}, #{hex.green.to_i}, #{hex.blue.to_i})"

# RGB to HSL
hsl = hex.to_hsl
puts "HSL: (#{hsl.hue.to_i}, #{(hsl.saturation * 100).to_i}%, #{(hsl.luminosity * 100).to_i}%)"

# RGB to CMYK
cmyk = hex.to_cmyk
puts "CMYK: (#{cmyk.c.round(2)}, #{cmyk.m.round(2)}, #{cmyk.y.round(2)}, #{cmyk.k.round(2)})"

Quick Setup

Library: color
gem install color

Ruby Tips & Best Practices

  • The color gem supports RGB, HSL, CMYK, and more
  • Use Color::RGB.by_hex to parse hex colors
  • to_hsl, to_cmyk, to_yiq conversions are built in

Frequently Asked Questions

Color Converter in Other Languages

More Ruby Tools