Created
August 25, 2014 18:12
-
-
Save tpitale/9e9ae2b87539bcd8963e to your computer and use it in GitHub Desktop.
Using default proc to deeply, arbitrarily nest new Hash
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
# http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-default_proc-3D | |
h = Hash.new {|hash, key| hash[key] = Hash.new(&hash.default_proc)} | |
h[:foo][:bar][:baz][:bat] = "hello" | |
p h | |
#=> {:foo=>{:bar=>{:baz=>{:bat=>"hello"}}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment