In Python, I can make a hash where each element has a default value when it's first referenced (also know as "autovivification"). Here's an example:
from collections import defaultdict
d = defaultdict(int)
d["new_key"] += 1
print d
Printing the dict shows the value for "new_key" is 1.
What's the equivalent in Ruby? This code throws an error:
d = {}
d[:new_key] += 1
puts d
test.rb:3:in `<main>': undefined method `+' for nil:NilClass (NoMethodError)