PRY GEM

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

then run:

bundle install

you can go ahead and load the console normally using:

rails console

Once you have the gem installed, you can enter into a session with pry, by just typing pry in your Terminal.

pry

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.

Example:

pry(main)> def hello
pry(main)*   puts "hello"
pry(main)* !
Input buffer cleared!

MANAGING HISTORY:

  1. Pry enables you to view, search, and replay history. Type the command:
hist
  1. The grep option is passed to hist only those lines which match the regular expression
    will be displayed.

Example:

pry(main)> hist --grep desc
1: $ describe
2: ? describe
  1. When the --tail N option is passed to hist only the last 'N' lines of history will be
    displayed.

Example:

hist --tail 5
  1. Similarly the head option in used to view first 'N' lines of history

Example:

hist --head 3
  1. 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)][1]

HELP SYSTEM

  1. To see the full list type 'help' at the prompt
  2. some commands have a more extensive help that can be accessed via typing:
command_name –help

View the complete documentation of PRY gem [here(Pry gem doc)][2]
[1]: https://github.com/pry/pry/wiki/History
[2]: https://github.com/pry/pry/wiki