Created
October 13, 2010 14:29
-
-
Save kv109/624128 to your computer and use it in GitHub Desktop.
Defining variable in methods declaration
This file contains 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
def method(var = 123) | |
var+=1 | |
end | |
def another_method(var) | |
var ||= 123 | |
var+=1 | |
end | |
method(nil) #first method raises <<undefined method `+' for nil:NilClass>> | |
another_method(nil) #but the second one does not |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment