Give pry a Try

One of the things holding us back from developing on Ruby 1.9.3 has been ruby-debug. There are issues with installing and running it, and while they are manageable, it makes it such that (on a Rails projects with a Gemfile) every user needs to then use 1.9.3 and the unreleased ruby-debug19 version. Not fun.

So after many people suggested we try it, we gave pry a shot. I don’t know why we didn’t before; it is quick, easy, and allows a wide range of Ruby versions.

On a Rails project, your install is simple. In your Gemfile remove anything related to ruby-debug and add in pry:

group :development, :test do
  gem "pry"
end

Then, anywhere you previously used debugger use pry instead.

For example, we frequently have a cucumber step for invoking the debugger:

When 'I debug' do
  pry
end

It is a little different from ruby-debug, but we’re loving it so far!

Update: banisterfiend points out in the comments:

If you use `binding.pry` instead of just `pry` you’ll get access to all the locals at the point you call it, too :)

Photo of Daniel Morrison

Daniel founded Collective Idea in 2005 to put a name to his growing and already full-time freelance work. He works hard writing code, teaching, and mentoring.

Comments

  1. January 17, 2012 at 4:38 AM

    Hi,

    If you use `binding.pry` instead of just `pry` you’ll get access to all the locals at the point you call it, too :)

  2. January 17, 2012 at 9:28 AM

    banisterfiend: great point! I’ve updated the post.