Created
July 11, 2014 14:42
-
-
Save sionide21/098d7b460983300d6487 to your computer and use it in GitHub Desktop.
Complex default parameters: Ruby vs Python
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 foo(a=[]): | |
a.append(1) | |
return a | |
foo() # => [1] | |
foo() # => [1, 1] | |
foo() # => [1, 1, 1] |
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 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