NameError: undefined - have parsing rules for local variables changed in Ruby 2.1.2?

后端 未结 3 2019
执笔经年
执笔经年 2021-01-18 07:31

I am getting NameError: undefined local variable or method with ruby 2.1.2

As observed in this question, expressions like:

bar if bar =          


        
3条回答
  •  不要未来只要你来
    2021-01-18 08:13

    Yes it changed in ruby 2.1.2

    In 1.8.7, 1.9.3, 2.0.0 and even 2.1.1 I get 2 warnings and no errors:

    2.0.0-p247 :007 > bar if bar = false
    (irb):7: warning: found = in conditional, should be ==
     => nil 
    2.0.0-p247 :008 > bar if bar = true
    (irb):8: warning: found = in conditional, should be ==
     => true 
    

    whereas in the 2.1.2 version you mention I get 2 warnings and 1 NameError error.

    2.1.2 :001 > bar if bar = true
    (irb):1: warning: found = in conditional, should be ==
    NameError: undefined local variable or method `bar' for main:Object
            from (irb):1
            from /home/durrantm/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `
    ' 2.1.2 :002 > bar if bar = false (irb):2: warning: found = in conditional, should be == => nil

    This is on my Ubuntu 14

提交回复
热议问题