weird behavior : string interpolation in return statement of next / break
MathieuDerelle opened this issue · 1 comments
MathieuDerelle commented
pry-byebug seems to alter next/break behaviors
using this snippet of code
a = 5
4.times.map do
a = 3
# next a
next "#{a}"
end
in string interpolation, the variable a
get the value of outside block 5
instead of 3
without string interpolation or using .to_s
, it keeps the value 3
➜ ~ pry
[1] pry(main)>
[2] pry(main)> a = 5
=> 5
[3] pry(main)> 4.times.map do
[3] pry(main)* a = 3
[3] pry(main)* # next a
[3] pry(main)* next "#{a}"
[3] pry(main)* end
=> ["5", "5", "5", "5"]
➜ ~ irb
2.2.5 :001 >
2.2.5 :002 > a = 5
=> 5
2.2.5 :003 > 4.times.map do
2.2.5 :004 > a = 3
2.2.5 :005?> # next a
2.2.5 :006 > next "#{a}"
2.2.5 :007?> end
=> ["3", "3", "3", "3"]
Versions used :
➜ ~ pry -v
Pry version 0.11.3 on Ruby 2.2.5
➜ ~ irb -v
irb 0.9.6(09/06/30)
Gemfile.lock :
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.5.0)
byebug (~> 9.1)
pry (~> 0.10)
pry-rails (0.3.6)
pry (>= 0.10.4)
(originally posted on pry : pry/pry#1717)
hegwin commented
Another issue for break
with a parameter:
In pry:
[1] pry(main)> a = [1,2,3]
=> [1, 2, 3]
[2] pry(main)> a.each do |num|
[2] pry(main)* break num if num > 2
[2] pry(main)* p num
[2] pry(main)* end
1
2
=> 3
In pry-byebug:
[1] pry(main)> a = [1,2,3]
=> [1, 2, 3]
[2] pry(main)> a.each do |num|
[2] pry(main)* break num if num > 2
ArgumentError: Cannot identify arguments as breakpoint
from /Users/hegwin/.rvm/gems/ruby-2.5.3/gems/pry-byebug-3.0.1/lib/pry/commands/breakpoint.rb:114:in `new_breakpoint'
[2] pry(main)* p num
[2] pry(main)* end
1
2
3
=> [1, 2, 3]