[Ruby] Regarding the mapping of hash key and value

less than 1 minute read

I couldn’t get the value of hash well, so I checked it and it was a little overlooked.

hash1 = {key: "value"} #=> {:key=> "value"}

When,

hash2 = {"key"=> "value"} #=> {"key"=> "value"}

Did not understand the difference between. The key name seems to change depending on the description method. In the example above

hash1["key"] #=> nil
hash1[:key] #=> "value"

become.

Tags:

Updated: