Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hash#default_proc as Default Value
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' } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment