You can inject a Pry REPL directly into somewhere that you want to debug.
1 |
pry -r ./stack.rb |
Here’s an example of runtime invocation:
test.rb
1 2 3 4 5 6 7 8 9 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ 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.
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.