Skip to content

Instantly share code, notes, and snippets.

@whitethunder
Created September 1, 2011 22:34
Show Gist options
  • Save whitethunder/1187487 to your computer and use it in GitHub Desktop.
Save whitethunder/1187487 to your computer and use it in GitHub Desktop.
ree-1.8.7-2011.03 :001 > a
NameError: undefined local variable or method `a' for #<Object:0x3466218>
from (irb):1
ree-1.8.7-2011.03 :002 > if false
ree-1.8.7-2011.03 :003?> a = 1
ree-1.8.7-2011.03 :004?> end
=> nil
ree-1.8.7-2011.03 :005 > a
=> nil
@quartzmo
Copy link

quartzmo commented Sep 1, 2011

Not sure but if you declare a method named 'a' instead, it behaves more consistently.

ruby-1.9.2-p290 :002 > a
NameError: undefined local variable or method a' for main:Object from (irb):2 ruby-1.9.2-p290 :003 > if false ruby-1.9.2-p290 :004?> def a ruby-1.9.2-p290 :005?> "" ruby-1.9.2-p290 :006?> end ruby-1.9.2-p290 :007?> end => nil ruby-1.9.2-p290 :008 > a NameError: undefined local variable or methoda' for main:Object
from (irb):8

@esogs
Copy link

esogs commented Sep 2, 2011

It does it for nil too, although maybe that is expected?

irb(main):001:0> a
NameError: undefined local variable or method `a' for main:Object
from (irb):1
from :0
irb(main):002:0> if nil
irb(main):003:1> a=1
irb(main):004:1> end
=> nil
irb(main):005:0> a
=> nil
irb(main):026:0> false.object_id
=> 0
irb(main):027:0> true.object_id
=> 2
irb(main):028:0> nil.object_id
=> 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment