Read more

Make your Rails console (and irb) output better readable

Dominik Schöler
March 13, 2012Software engineer at makandra GmbH

On modern Rubies, the IRB's inspection supports syntax highlighting (1.2+) and multi-line output for larger objects (1.3.1+).

You can gem install irb to update your IRB on any Ruby 2.5+.

Pour color on your Rails console with awesome_print Show archive.org snapshot . Turn confusing long strings into formatted output. Have objects and classes laid out clearly whenever you need it.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Put gem 'awesome_print', :group => :development into your Gemfile. Now on the Rails console you have the command ap that will give you a colored, formatted output of whatever you pass it. See the example output of the User class below.

For customization visit the repository on Github.

awesome_print.png

Remark

Note that there are other ways to print data in a structured way. Ruby's pretty-print library pp handles formatted printing (you might need to require 'pp'). Pry Show archive.org snapshot will give you a readable output, too. If it's already used in your project, you probably won't need to use awesome_print either.

Posted by Dominik Schöler to makandra dev (2012-03-13 10:25)