Skip to content

Instantly share code, notes, and snippets.

@tpitale
Created August 25, 2014 18:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpitale/9e9ae2b87539bcd8963e to your computer and use it in GitHub Desktop.
Save tpitale/9e9ae2b87539bcd8963e to your computer and use it in GitHub Desktop.
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