ruby drive-by: autovivification
need multi-level hashes in a hurry? (assumes 1.9)
h = Hash.new {|h,k| h[k] = Hash.new(&h.default_proc)}
h["foo"]["bar"]["baz"] = 42
h["foo"] #=> {"bar"=>{"baz"=>42}}
10 months ago
need multi-level hashes in a hurry? (assumes 1.9)
h = Hash.new {|h,k| h[k] = Hash.new(&h.default_proc)}
h["foo"]["bar"]["baz"] = 42
h["foo"] #=> {"bar"=>{"baz"=>42}}
10 months ago