问题
I'm trying to use pry and pry-byebug to step through the execution of some code in a Rails console. I started the console with
pry -r ./config/environment
I then set a breakpoint:
break Foo#bar
Then make a new Foo
and call bar
on it:
Foo.new.bar
I expected step into Foo#bar
, but instead the method just executed normally.
Is there some way to get this workflow to work?
回答1:
I found the answer: the debugger is not re-entrant. So you need to do this:
[1] pry(main)> binding.pry
[1] pry(main)> break Foo#bar
Breakpoint 1: Foo#bar (Enabled) :
6: def bar
7: end
[2] pry(main)> c # continue and exit the debugger we started on the first line
=> nil
[3] pry(main)> Foo.new.bar
Breakpoint 1. First hit.
回答2:
Here is how I usually use pry-byebug
Add a call to binding.pry
to the first line of the method Foo#bar
Run rails console
Call Foo.new.bar
You should see the pry REPL now
来源:https://stackoverflow.com/questions/38965956/breakpoints-with-pry-byebug-dont-trigger-in-the-console