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 #145

Open
MathieuDerelle opened this issue Dec 1, 2017 · 1 comment

Comments

@MathieuDerelle
Copy link

MathieuDerelle commented Dec 1, 2017

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

hegwin commented Feb 27, 2019

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]

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