Collective Idea

Collective Idea Logo

Daniel Morrison

Give pry a Try

By Daniel Morrison on January 16, 2012 in debugger, pry, rails, and ruby

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

By Daniel Morrison on January 16, 2012 in debugger, pry, rails, and ruby

2 Comments

  1. banisterfiend

    banisterfiend January 17, 2012 http://https://github.com/banister

    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. Daniel Morrison

    Daniel Morrison January 17, 2012 http://collectiveidea.com

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

Post a Comment

Contact Us

Find us on Google Maps
Collective Idea
25 West 8th Street, Suite 200
Holland, Michigan 49423 USA 42.790299-86.108415

Follow us on the Interwebs

We are currently available for medium and long term projects. Please get in touch if we can be of service.