Make Byebug finish executing without exiting Pry Make Byebug finish executing without exiting Pry ruby ruby

Make Byebug finish executing without exiting Pry


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.


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


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  superend

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.