Skip to content

Instantly share code, notes, and snippets.

@mehdi-farsi
Created April 29, 2018 17:47
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 mehdi-farsi/de96058c7bb027593f31221c03e31045 to your computer and use it in GitHub Desktop.
Save mehdi-farsi/de96058c7bb027593f31221c03e31045 to your computer and use it in GitHub Desktop.
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