Bug #11115
Updated by nobu (Nobuyoshi Nakada) about 9 years ago
Here's what normally happens when I try to reference a local variable that doesn't exist: ~~~ruby ~~~ def foo bar end foo # => NameError: undefined local variable or method `bar' ~~~ But if I assign bar to "itself", it doesn't raise an error ~~~ruby ~~~ def foo bar = bar bar end foo # => no results ~~~ Looks like `bar` in the second example is being set to `nil`. This doesn't feel very intuitive to me; shouldn't this raise an error? I mean, if you try to assign the non-existent variable 'bar' to anything else, that's how it works: ~~~ruby ~~~ def foo fizz = bar end foo # => NameError: undefined local variable or method `bar' ~~~ Is this a bug, or a feature?