layers = Hash.new { |layers, layer_name| layers[layer_name] = Hash.new(&layers.default_proc) }
layers[:layer_1][:layer_2][:layer_3] = 'a secret'
layers # => { layer_1: { layer_2: { layers_3: 'a secret' } } }
Created
April 29, 2018 17:47
-
-
Save mehdi-farsi/de96058c7bb027593f31221c03e31045 to your computer and use it in GitHub Desktop.
Hash#default_proc as Default Value
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment