Skip to content

Instantly share code, notes, and snippets.

@kv109
Created October 13, 2010 14:29
Show Gist options
  • Save kv109/624128 to your computer and use it in GitHub Desktop.
Save kv109/624128 to your computer and use it in GitHub Desktop.
Defining variable in methods declaration
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