Confused in assigning default value in hash

no_nil_hash={"p" =>"as",
"s" =>"sad",
"f" =>"dsaf"
puts no_nil_hash["k"]
It is showing output as nil


That's because you define the no_nil_hash twice:

Once it's an empty hash with a default value of "tree".

Then it's replaced by a filled hash, but with a default value of nil.

So of course when you ask for a non-existing key it will return nil.

#3 was very helpful..Thank you