Created
September 28, 2011 13:49
-
-
Save nel/1247975 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foo # NameError: undefined local variable or method `foo' for main:Object | |
foo = "bar" unless defined?(foo) | |
foo # => nil |
Yep, it's ok in the case you want scope wide memoization on that variable. But you are right we are diverging the purpose of the gist/comments was just to expose corner case in ruby language.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
instance variable in class methods is a an class instance variable, so it should work even if its not really beautiful in many cases.
Anyway , my answer was not to give a solution but to show that the behaviour wasn't happen with instance variable.
Im not sure but Ii think its because local variable are defined in scope at parsing (when affected a value) what is not for ivars.