awesome_print pretty prints/formats Ruby objects.
This post focuses on having awesome_print enabled in the rails console without changing/updating the Gemfile. This way it is available in all Rails applications and consoles.
You can always add the gem to the Gemfile and have this working for that specific rails application.
gem 'awesome_print', :require => 'ap'
To set it up, you need to install the gem
gem install awesome_print
To find the path for the gem. issue the following command
gem which awesome_print
If you use rbenv or rvm, you will need to add it to the load path in ~/.irbrc
With this done, you can use the AwesomePrint’s ap method to pretty print the Ruby objects in the console.
console> ap User.first
If you want to set up awesome_print as the default formatter in Rails console, you will need to call the following method in ~/.irbrc or ~/.pryrc if you use pry.
This way you won’t have to use the ap method to make the objects pretty. They will be awesome by default 🙂
That is it.
Enjoy pretty printing your Ruby objects.