How do I step out of a loop with Ruby Pry?

前端 未结 9 1134
醉话见心
醉话见心 2020-12-22 15:11

I\'m using Pry with my Rails application. I set binding.pry inside a loop in my model to try and debug a problem. For example:

(1..100).each do          


        
9条回答
  •  -上瘾入骨i
    2020-12-22 15:45

    A binding.pry statement is exactly the same as a breakpoint in GDB. Such a breakpoint in GDB would be hit 100 times too.

    If you only want the binding.pry to be hit once, for the first iteration of the loop, then use a conditional on the binding.pry like so:

    (1..100).each do |i|
      binding.pry if i == 1
      puts i
    end
    

    You then exit the current session by just typing exit.

提交回复
热议问题