RUBY: Colorful Code Runs Better- its cyantifically proven 🎨

Kyle Conlon
4 min readJul 14, 2019

--

by Kyle Conlon

Do you prefer every screen you look at to simply display Black and White, like you live in the 1940's? Do you enjoy the mundane readout of white words on a black background, which likely slows down your workflow due to command confusion and eye-fatigue? Do you hate rainbows?

If so, then stop reading right here and go back to your home on bore-island.

That’s the line, right?

Enter “Colorize”, “Rainbow”, & “Lolize”- ruby gems designed to add a unique flair of color to your console so that your command line output doesn’t look like 💩. These gems are perfect for making small CLI projects even more fun.

Colorize is a string class extension which provides a user with additional methods that allow you to change a string’s text color, background color, and even create text effects (like blinking) using ANSI escape sequences. It can also display color samples and disable colorization as well.

One of the best aspects of this gem is its incredible ease of use. Simply add the gem “colorize” to your Gemfile and begin your coloring rampage via dot notation.

.light_magenta for pink text color

You also have the ability to colorize the text background just as easily, using (.on_color-name-here) chained after the text color.

.on_green for a green background!

And here are all available colors for the colorize gem:

The gem “Rainbow” is very similar to Colorize, but you have access to many, many more colors and color options. Implementation is also exactly the same- add the gem to your Gemfile and require ‘Rainbow’ at the top of the necessary file.

Rainbow contains the following methods for all of your coloring customization needs:

Color(c), Background(c), bright, underline, blink, inverse, hide, faint, italic, cross_out, and strike.

And their color selection is absolutely absurd:

Another great feature- Rainbow uses dot notation just like Colorize, but offers you the ability to chain those above methods with any of their colors as well, for even more color customization.

The gem “Lolize” is slightly different (in the best way possible), where instead of selecting exactly which color you’d like for each individual string- it turns every line it’s thrust upon into a beautiful rainbow gradient. You’ll have to see it to believe it.

To install “Lolize” simply place the gem in your gemfile and at the top of file where you’ll be using it, either type [require ‘lolize/auto’] for ALL output to turn into rainbowy goodness or just [require ‘lolize’] to be able to control which lines you specifically want colored. In that case, you’ll need to implement the gem like so:

gem 'lolize'
require 'lolize'
colorizer = Lolize::Colorizer.new
colorizer.write "Hello, World\n"*5
puts "I AM WHITE" # This is clean

--

--

Kyle Conlon

Musician turned Programmer // Focused in Front End Development using React, React Native, Rails, & Node