Skip to content

Instantly share code, notes, and snippets.

@Hampei
Created October 10, 2018 10:18
Show Gist options
  • Save Hampei/084d0fc93c37b19df7d87fd9405f0b28 to your computer and use it in GitHub Desktop.
Save Hampei/084d0fc93c37b19df7d87fd9405f0b28 to your computer and use it in GitHub Desktop.
quick one-line hash creation with a default of a hash with a default of a hash with a default of a hash ...
my_hash = Hash.new {|h,k| h[k] = Hash.new(&h.default_proc) }
my_hash.dig('foo', 'bar', 'bla')
=> {}
my_hash
=> {"foo"=>{"bar"=>{"bla"=>{}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment