Skip to content

Instantly share code, notes, and snippets.

@pdobb
Last active May 25, 2023 05:19
Show Gist options
  • Save pdobb/370ab06a744af58360a2 to your computer and use it in GitHub Desktop.
Save pdobb/370ab06a744af58360a2 to your computer and use it in GitHub Desktop.
Use AwesomePrint in Rails Console without adding to Gemfile
AwesomePrint.defaults = {
:indent => -2,
:color => {
:string => :greenish,
:date => :yellowish,
:time => :yellowish,
:nilclass => :cyanish
}
}
# Determine the load path for your system by running `gem which awesome_print`;
# remove `awesome_print.rb` from the end of the output.
$LOAD_PATH << '/Users/pdobb/.gem/ruby/1.9.3/gems/awesome_print-1.6.1/lib/'
require "awesome_print"
@pdobb
Copy link
Author

pdobb commented Aug 21, 2015

Instructions:

  1. Install AwesomePrint gem:
    gem install awesome_print
  2. Add AwesomePrint to the LOAD_PATH for your console sessions. Using pry, we can this to ~/.pryrc as shown above.
  3. Add formatting options for AwesomePrint to ~/.aprc as shown above.
  4. In the Rails Console, prefix whatever query method you want with ap.

image

@fakefarm
Copy link

fakefarm commented Apr 14, 2022

YES! Thank you! 🍻

I couldn't figure out how to get the load path into .irbrc until you showed me gem which [gem_name]

@pdobb
Copy link
Author

pdobb commented May 25, 2023

@fakefarm No problem. Although I've since learned that you can just do gem "awesome_print" to load the gem. For example:

begin
  gem 'awesome_print'
  require 'awesome_print'
  AwesomePrint.pry!
rescue Gem::LoadError
  puts 'The "awesome_print" gem is not installed. Skipping AwesomePrint.pry!'
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment