Given the following code:
require 'pry-byebug'
10.times.with_index do |i|
binding.pry
puts i
end
I'd like to "loop until i == 5
then break" while inside pry-byebug
. From running it help break
it seems like you can identify breakpoints by "breakpoint #" or "line #". It also seems like you can use conditions, however I'm not getting it to work:
Trying to set breakpoint on line #:
$ ruby foo.rb
From: /Users/max/Dropbox/work/tmp/pry_debug/foo.rb @ line 5 :
1: require 'pry-byebug'
2:
3: 10.times.with_index do |i|
4: binding.pry
=> 5: puts i
6: end
[1] pry(main)> break foo.rb:5 if i == 5
Breakpoint 1: /Users/max/Dropbox/work/tmp/pry_debug/foo.rb @ 5 (Enabled) Condition: i == 5
2:
3: 10.times.with_index do |i|
4: binding.pry
=> 5: puts i
6: end
[2] pry(main)> continue
0
From: /Users/max/Dropbox/work/tmp/pry_debug/foo.rb @ line 5 :
1: require 'pry-byebug'
2:
3: 10.times.with_index do |i|
4: binding.pry
=> 5: puts i
6: end
[2] pry(main)> i
=> 1
First setting breakpoint then putting condition on break point:
➜ ~/D/w/t/pry_debug ruby foo.rb
From: /Users/max/Dropbox/work/tmp/pry_debug/foo.rb @ line 5 :
1: require 'pry-byebug'
2:
3: 10.times.with_index do |i|
4: binding.pry
=> 5: puts i
6: end
[1] pry(main)> break foo.rb:15
Breakpoint 1: /Users/max/Dropbox/work/tmp/pry_debug/foo.rb @ 15 (Enabled)
[2] pry(main)> break --condition 1 i == 5
[3] pry(main)> c
0
From: /Users/max/Dropbox/work/tmp/pry_debug/foo.rb @ line 5 :
1: require 'pry-byebug'
2:
3: 10.times.with_index do |i|
4: binding.pry
=> 5: puts i
6: end
[3] pry(main)> i
=> 1
As you can see, in both cases pry-byebug
doesn't respect the condition because it stops too soon. How do I get it to work?