Skip to content

Instantly share code, notes, and snippets.

@orend
Last active December 15, 2015 03:39
Show Gist options
  • Select an option

  • Save orend/5196398 to your computer and use it in GitHub Desktop.

Select an option

Save orend/5196398 to your computer and use it in GitHub Desktop.
default values to hashes (from ruby tapas)
# 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