In Ruby, why after starting irb, foo.nil? says undefined error, and @foo.nil? gives "true", and @@wah.nil? gives error again?

Viewed 1426

Same in Ruby 1.8.7 and 1.9.2:

$ irb

ruby-1.8.7-p302 > foo.nil?
NameError: undefined local variable or method `foo' for #<Object:0x3794c>
    from (irb):1

ruby-1.8.7-p302 > @bar.nil?
 => true 

ruby-1.8.7-p302 > @@wah.nil?
NameError: uninitialized class variable @@wah in Object
    from (irb):3

why the instance variable treated differently than a local and class variable?

1 Answers
Related