Breakpoints with pry-byebug don't trigger in the console

给你一囗甜甜゛ 提交于 2019-12-24 00:44:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!