Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weird behavior : string interpolation in return statement of next / break #1717

Closed
MathieuDerelle opened this issue Nov 22, 2017 · 5 comments

Comments

@MathieuDerelle
Copy link

MathieuDerelle commented Nov 22, 2017

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
Copy link
Member

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
Copy link
Member

What other Pry plugins are you running?

@MathieuDerelle
Copy link
Author

MathieuDerelle commented Nov 23, 2017

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
Copy link
Member

It's possibly due to pry-byebug which overrides the next keyword. Try uninstalling pry-byebug and do it again :)

@MathieuDerelle
Copy link
Author

good idea. Everything was normal without pry-byebug

I've send them the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants