Skip to content

Instantly share code, notes, and snippets.

@rayway30419
Created March 1, 2018 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayway30419/eee662e359c840b27e4786205aac1c12 to your computer and use it in GitHub Desktop.
Save rayway30419/eee662e359c840b27e4786205aac1c12 to your computer and use it in GitHub Desktop.
Hash#default_proc
deep_hash = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) }
deep_hash[:a][:b][:c][:d] = 'Hello World'
puts deep_hash
# {:a=>{:b=>{:c=>{:d=>"Hello World"}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment