Skip to content

Instantly share code, notes, and snippets.

@psychocandy
Created February 17, 2013 13:57
Show Gist options
  • Save psychocandy/4971593 to your computer and use it in GitHub Desktop.
Save psychocandy/4971593 to your computer and use it in GitHub Desktop.
Autovivification which allows you to nest away and save you a lot of nil? checks.
hash = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) }
hash[:foo]["bar"][:baz] = 13
# => {:foo=>{"bar"=>{:baz=>13}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment