Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using default proc to deeply, arbitrarily nest new Hash
# 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
You can’t perform that action at this time.