How to make your Rake Console not look like an Eyesore

Maleeha Bhuiyan
2 min readJun 15, 2020

Generally when one wants to play around with data using the rake console, the data will output like this:

With two elements in this array, it does not look that bad. But what if you can output this information in a table via Ruby?

This looks looks much better! However, since we are only dealing with 2 elements, the difference may not seem so vast. Let’s look at an example where we are dealing with a larger quantity of data.

This array has way more than 2 elements, the data can look intimidating to few, and is not easy on the eyes for many. Let’s bring out the table:

This looks like a cleaner way to represent the data! The steps to do this are quick and easy.

Step 1: Add the appropriate gem

In the file where you keep your gems. Add the gem: gem ‘hirb’, ‘~>0.7.0’ . The hirb gem is primarily used to improve output when given an object or an array.

Step 2: Set up your require method

In your run file, add: require ‘hirb’ . This will let the run file execute contents from hirb.

Step 3: Add this code

In addition to the require method, copy and paste this code onto your run file.

Hirb.enable

old_print = Pry.config.print

Pry.config.print = proc do |output, value|

Hirb::View.view_or_page_output(value) || old_print.call(output, value)

end

It should look exactly like this. Make sure to save your work. Once it is saved, run a fresh rake console and watch your once cluttered looking data transform into an easy to read table!

--

--