Make Byebug finish executing without exiting Pry

佐手、 提交于 2019-12-06 18:15:21

问题


When I set a breakpoint with Byebug in Rails, I sometimes want it to finish executing, but the guide on github says to use exit which also exits Pry. Typing continue repeatedly can be annoying if the breakpoint is in a loop.

Is there anyway to stop byebug without exiting the Rails console?


回答1:


When running byebug under the Rails console or in Rails' server I usually quit only byebug by hitting Ctrl+D.

The catch with this approach is, if you do this in Rails' server then Byebug will not stop and debug the next time it hits a byebug statement in your code anywhere. But it works perfectly in the Rails console.




回答2:


Try !!!. It works on pry gem, but not sure if it does on byebug.




回答3:


Well this isn't the most elegant solution but it works for me so far.

If you have a base controller in your rails application you can add an accessor to hold a variable saying whether you want debugging to happen or not:

attr_accessor :debugging

Then add/modify initializer to set the variable to true on each request (or each time there is an instance created for that object):

def initialize
  @debugging=true
  super
end

And finally, always use the byebug call with a conditional wherever you want this behavior:

byebug if debugging

Then when you are at the IRB console and you want to exit the debugger but continue executing the code you just set the variable:

@debugging=false; finish

You could even encapsulate this in a helper or do some OOP magic but this is a good starting point. Nice thing is that if you repeat the request you'll get the standard behavior again unless you set the variable to false again.




回答4:


Typing finish in the console exits byebug, without closing pry/rails console/rails server.

Ctrl + D also works.




回答5:


Remove "debugger from your code and type in "finish" in console



来源:https://stackoverflow.com/questions/30627186/make-byebug-finish-executing-without-exiting-pry

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