Skip to content

Instantly share code, notes, and snippets.

@ShadowBelmolve
Created October 11, 2012 16:47
Show Gist options
  • Save ShadowBelmolve/3873791 to your computer and use it in GitHub Desktop.
Save ShadowBelmolve/3873791 to your computer and use it in GitHub Desktop.
Autovivification hash
deep = Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) }
# {}
deep[:foo][:bar][:lol?][:win!] = 10
# 10
deep
# {:foo=>{:bar=>{:lol?=>{:win!=>10}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment