Created
October 10, 2018 10:18
-
-
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 ...
This file contains 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
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