Skip to Content Collective Idea Home

Give pry a Try

by Daniel Morrison

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 :)

Comments

banisterfiend
::

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 :)


Daniel Morrison
::

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