2

I am using inline byebug to stop the program execution and debug, from rails console or from a running rails server.

I have to debug a very repetitive loop, and I need to put a byebug in the middle of that loop.

After debugging, it seems my options are either to keep pressing c until I can get out of my loop, or abort the console execution execution with exit or something similar. But then I need to reload the whole environment.

Is it possible to just tell byebug to skip next byebug lines until the request (rails server) or until the command (rails console) finishes ?

Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164
  • 1
    you could try doing `byebug if ` and that code might include manually setting a variable to true when rails server started successfully. – jeroenvisser101 May 05 '16 at 13:32

1 Answers1

1

I do this a couple ways:

1.

large_array.each.with_index do |item, index|
  byebug if index == 0    #  or any other condition, e.g. item.some_method?
  # ...
end
  1. byebug before the loop, set a breakpoint using b <line_number>. You can clear the breakpoint later at one of the prompts.
Andrew Schwartz
  • 4,440
  • 3
  • 25
  • 58
  • In some cases I actually don't have control of the loop itself. The loop is from an external library, and my custom code gets called inside the loop (inversion of control). Also your first way involve modifying the rest of the code in case there is no index generated from the loop. I do like your way n°2 though (but only when you have control of the before-loop). – Cyril Duchon-Doris May 05 '16 at 14:11
  • 1
    Gotcha. Oddly I can't find a way to disable byebug like you can for pry. Here's an idea: use some named class variable inside your code, say `@@suppress_byebug`. Then `byebug if !defined? @@supress_byebug`. Then set the variable from inside byebug when you want the madness to stop. Would that work? – Andrew Schwartz May 05 '16 at 15:35