Default value in hash using default
A hash contains key and value. If the key is not found then hash returns nil. Let’s see it in action.
As we can see the hash does not have a key called
age and hash returned
That’s what hash does by default.
However we can tell Hash to return some other default value.
This time we got 0. This is because we changed the default value of hash to zero.