Writing Hash with a default value using the literal method instead of Hash.new?


I want to write out my hash using the literal method instead of using Hash.new.

How do I set the default value to 0 in this writing style?
I've tried variations on:

frequencies = {0}

with no luck :frowning:


it should be like that

frequencies = Hash.new(0)


@wizmarco I don't think you completely understood the question that I was asking. While your answer solves the exercise, I wanted to solve it in a different way.

As it turns out, the solution I was looking for involved calling a method on frequencies that I wasn't aware of.

The solution for anyone else who comes across this question is:
frequencies = {}
frequencies.default = (0)

Since a hash calls for a (key,value) pair, you can't enter in just 1 value, but rather should leave it nil and then specify its default value. It just requires an additional line to specify the default method.