weird behavior : string interpolation in return statement of next / break
Closed this issue · 5 comments
MathieuDerelle commented
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"]
2.2.5 :008 > quit
Versions used :
➜ ~ pry -v
Pry version 0.11.3 on Ruby 2.2.5
➜ ~ irb -v
irb 0.9.6(09/06/30)
banister commented
I can't reproduce this incorrect behaviour on 2.2.5 and Pry:
[1] pry(main)> RUBY_VERSION
=> "2.2.5"
[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)* end
=> ["3", "3", "3", "3"]
[4] pry(main)>
banister commented
What other Pry plugins are you running?
MathieuDerelle commented
pry-rails and pry-debug
from 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)
banister commented
It's possibly due to pry-byebug
which overrides the next
keyword. Try uninstalling pry-byebug
and do it again :)
MathieuDerelle commented
good idea. Everything was normal without pry-byebug
I've send them the issue