why the default value didn’t change at the first example but didn’t change at the second I think the default value shoudn’t have been changed at both examples:
Hash.new(object) always returns the same object as a default. This is why you get [1] for the key “b” because it’s the same array. For an integer it works differently because you are not modifying the integer but replacing the value. It’s basically hash[“b”] = hash[“b”] + 1.
What you want to do instead, is passing the default in a block: Hash.new { }
This will evaluate block everytime a key has no value, so you’ll get a new array everytime.