Learn Ruby
Hash
15.8
Lesson

Default value in hash using new

In the previous lesson we saw how we can use hash.default = 0 to ensure that hash returns value 0 if the key is missing.

The default value can be set to hash using Hash.new also.

This time we got 0. This is because we changed the default value of hash to zero by setting the value when we performed Hash.new.