Skip to content

Instantly share code, notes, and snippets.

@levity
Created December 14, 2010 21:49
Show Gist options
  • Save levity/741170 to your computer and use it in GitHub Desktop.
Save levity/741170 to your computer and use it in GitHub Desktop.
Infinite Hash
# O.o
# http://opensoul.org/blog/archives/2010/12/12/the-ruby-infinite-hash/
>> hash = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
=> {}
>> hash['a'] = 1
=> 1
>> hash['a']
=> 1
>> hash['b']
=> {}
>> hash['b']['c']['d']
=> {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment