Pry – Part 4 – Debugger

You can inject a Pry REPL directly into somewhere that you want to debug.

pry -r ./stack.rb

Here’s an example of runtime invocation:

test.rb

require 'pry'
# set x to 10
x = 10

# start a REPL session
binding.pry

# program resumes here (after pry session)
puts "program resumes here. Value of x is: #{x}."

when run using ruby test.rb:

$ ruby test.rb 

From: /Users/snowcrash/Developer/Ruby/Pry/test.rb @ line 6 :

    1: require 'pry'
    2: # set x to 10
    3: x = 10
    4: 
    5: # start a REPL session
 => 6: binding.pry
    7: 
    8: # program resumes here (after pry session)
    9: puts "program resumes here. Value of x is: #{x}."

[1] pry(main)> 

So, code is shown around the REPL invocation line with a cursor showing where the runtime has stopped.

http://pryrepl.org

For the best source of Pry documentation: https://github.com/pry/pry/wiki

For more on Pry at runtime, see Pry – Part 5 – Pry at runtime.

Leave a Reply

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