pry it open with pry

Wow. Did i already mention how i love pry?

I like crowbars and hammers and this is the perfect tool to get into the guts of your code – wherever you want to. Follow these simple steps.

Add to your Gemfile (assuming ruby>1.9.2)

group :development do
  gem 'pry'
  gem 'pry-debugger'

Then pry your code open.
Given a method

def rock_an_item(item)

add binding.pry,

def rock_an_item(item)

Run again and voilá

From: testit.rb @ line 10 Object#rock_an_item:

    10: def rock_an_item(item)
 => 11:   binding.pry
    12:   do_this(item)
    13:   do_that(item)
    14: end

[1] pry(main)> 

you’re dropped right into an irb console at the point of the break. With pry-debugger installed you have step, next, continue methods (and more). Investigate your item, check out your environment, when it’s all done, continue. Fix the bug, remove binding.pry and move on. Super simple.

Sadly, the debugger tie-in and 1.8.7 is not quite as seamless. I’m still working on that. But assuming most of your projects have moved into the 1.9.x realm, you should be in good shape.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s