Skip to content

Instantly share code, notes, and snippets.

@sionide21
Created July 11, 2014 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sionide21/098d7b460983300d6487 to your computer and use it in GitHub Desktop.
Save sionide21/098d7b460983300d6487 to your computer and use it in GitHub Desktop.
Complex default parameters: Ruby vs Python
def foo(a=[]):
a.append(1)
return a
foo() # => [1]
foo() # => [1, 1]
foo() # => [1, 1, 1]
def foo(a=[])
a << 1
end
foo # => [1]
foo # => [1]
foo # => [1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment