Pry Yourself Away from IRB

PryFor the past couple of weeks I’ve switched to using “pry”:http://pry.github.com as my rails console / IRB replacement. I am loving it so far.

bq. Pry is a powerful alternative to the standard IRB shell for Ruby. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing.

The subtleties of pry alone make it an improvement over the vanilla IRB:

* Automatically paginate large return values
* Add syntax highlighting to return values
* Allow for easily hiding return values with ‘;’

But wait, there’s more! Try pry now and we’ll throw in:

* Easily execute shell commands with the . prefix
* Allow for history management with save and replay capabilities
* A powerful way of exploring your code using shell based ideas such as cd and ls
* Easy integration with Rails 2 or 3
* Remote connections coming soon

If you’re like me you want an example:
I do some playing around with “Gosu”:http://www.libgosu.org/, but I always forget the keyboard key constants.

In pry I can simply type:

pry(main)> cd Document.first/@attributes
pry(#):2> keys.sort
=> ["actual_finish_at",
  "actual_start_at",
  "adjusted_planned_finish_at",
  "adjusted_planned_start_at", ...

Or when working in a Rails console:

pry(main)> ls -c --grep Kb Gosu
 Kb0  Kb1  Kb2  Kb3  Kb4  Kb5  Kb6  Kb7  Kb8  Kb9  KbA  KbB  KbBackspace  KbC  KbD  KbDelete  KbDown  KbE  KbEnd  KbEnter ...

For more in-depth examples check out the “rails cast”:http://railscasts.com/episodes/280-pry-with-rails and the “pry wiki”:https://github.com/pry/pry/wiki.

Conversation
  • […] for navigating objects in your running application. It also has an extensible plugin system. I’ve written about pry before on this blog. Over the last few months, I’ve found a few new nuggets of pry goodness that […]

  • Comments are closed.