A miscellaneous note of what I learned from the Cherry book. Since ruby's hash only returns nil even if you call a key that does not exist, it is difficult to notice the mistake, so I tried to output an explicit message.
hash = Hash.new('A key that does not exist.')
hash.merge!({key1: :value1})
hash[:key1]
# => :value1
hash[:key2]
# => "This is a non-existent key."
Recommended Posts