Pry

Note: you’ll need to install pry and pry-debugger.

Note also: you may come across pry-nav which is an older project and, if you’re using MRI 1.9.2+, they recommend you use pry-debugger.

1. 

require ‘pry’   # note that Rails auto loads stuff but if you’re just using plain old Ruby then you’ll need to manually load this…

require ‘pry-debugger’

2. then start a REPL session with

binding.pry

So, what is binding? Basically objects of class Binding encapsulate the execution context at some particular place in the code and retain this context for future use but see the docs:

http://ruby-doc.org/core-2.0/Binding.html

3. and step through with ‘step’

Notes:

1. Local variables are available to a Pry session (locals are not available to an irb session when using irb -r)

2. When you end a Pry session it returns to the running program; very useful for debugging

See also: 

http://banisterfiend.wordpress.com/2011/01/27/turning-irb-on-its-head-with-pry/

and

http://knomedia.com/blog/2013/01/21/debugging-ruby-with-pry/

Leave a Reply

Your email address will not be published. Required fields are marked *