Last active
December 15, 2015 03:39
-
-
Save orend/5196398 to your computer and use it in GitHub Desktop.
default values to hashes (from ruby tapas)
This file contains hidden or 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
| # a default value of array allows us to implicitly initialize accessed fields | |
| h = Hash.new{ |h ,k| h[k] = []} | |
| h['a'] << "c" | |
| h['a'] << "d" | |
| >> h | |
| { | |
| "a" => [ | |
| [0] "c", | |
| [1] "d" | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment