Created
November 15, 2013 22:18
-
-
Save jphenow/7492604 to your computer and use it in GitHub Desktop.
WTF default value hash
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
2.0.0p247 :021 > h = Hash.new([]) | |
# => {} | |
2.0.0p247 :022 > h[:test] | |
# => [] | |
2.0.0p247 :023 > h[:test] << "h" | |
# => ["h"] | |
2.0.0p247 :024 > h | |
# => {} | |
2.0.0p247 :025 > h.values | |
# => [] | |
2.0.0p247 :026 > h.keys | |
# => [] | |
2.0.0p247 :027 > h[:test] | |
# => ["h"] | |
2.0.0p247 :028 > h[:something_else] | |
# => ["h"] | |
# So the shoveling of the "h" is modifying the default value (array on line 1) in place. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment