Write keys and values in Ruby

Based on the three types of reference, the types of key and value are summarized below.

1. hash1 = {"title" => "Weathering with You"}

2. hash2 = {: title => "Weathering with You"}

3. hash3 = {title: => "Weathering with You"}

hash1 uses a string as a key.

hash2 and hash3 use symbols as keys.

hash2 and hash3 have the same content, but hash3 </ strong> is the simplest way to write.

When used as a hash key, the symbol is recommended because it runs faster </ strong>.

Recommended Posts