Pry is a powerful alternative to the standard IRB shell for Ruby. It is a REPL (it reads, evaluates, prints, loops). Pry’s advantages over irb are Pry adds additional features such as syntax-highlighting, managing history, Live help system etc.
CONFIGURE YOUR RAILS APP TO USE PRY INSTEAD OF IRB:
Add this line to your gemfile:
gem 'pry-rails', :group => :development
you can go ahead and load the console normally using:
Once you have the gem installed, you can enter into a session with pry, by just typing pry in your Terminal.
CLEARING INPUT BUFFER
Sometimes the parsing process can go wrong while entering a multi-line expression, and the read loop will never terminate. Entering the !character on a line by itself will clear the input buffer and break out of the read loop.
pry(main)> def hello pry(main)* puts "hello" pry(main)* ! Input buffer cleared!
- Pry enables you to view, search, and replay history. Type the command:
- The grep option is passed to hist only those lines which match the regular expression
will be displayed.
pry(main)> hist --grep desc 1: $ describe 2: ? describe
- When the --tail N option is passed to hist only the last 'N' lines of history will be
hist --tail 5
- Similarly the head option in used to view first 'N' lines of history
hist --head 3
- To disable saving of history use the following command:
Pry.config.history.should_save = false
Read more on managing history with pry gem [here(pry history doc)]
- To see the full list type 'help' at the prompt
- some commands have a more extensive help that can be accessed via typing:
Subscribe to Engineering At Kiprosh
Get the latest posts delivered right to your inbox