11

Sometimes I'm stuck in a long loop when using binding.pry. I can quit the loop by exit-program, but the command exit rails console also.

Is there easy way to exit a long loop without quitting rails console?

ironsand
  • 14,329
  • 17
  • 83
  • 176

2 Answers2

9

I'm not sure this is what you're looking for but you may want to try the disable-pry command which will automatically iterate though your entire loop without exiting the session. Another option (albeit not great for long loops) would be to use exit or Ctrl+D which iterates through a single cycle of a loop. You would have to enter it repeatedly until your loop was complete, however it would allow you to hit another breakpoint if that's your goal.

For a little more control you may want to add another gem like byebug or pry-byebug.

Dom
  • 160
  • 2
  • 10
  • 1
    And then, if you want to re-enable breaking on `binding.pry` after getting out of your loop, use `ENV['DISABLE_PRY'] = nil`. There is no `enable-pry` command, but this does the trick. – Francesca Nannizzi Sep 17 '18 at 15:18
0
debug = true
# start loop
    binding.pry if debug
# end loop

You can exit each loop iteration individually with exit. Then, when you're ready to step out of debugging and continue the execution of the remaining code, enter debug = false. Then, exit will return you to the rails console session.

Walter
  • 397
  • 4
  • 11