[Ruby] Writing keys and values in Ruby

less than 1 minute read

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

1. hash1 = {"title" => "weather child"}

2. hash2 = {:title => "weather child"}

3. hash3 = {title: => "weather child"}

hash1 uses strings as keys.

hash2 and hash3 use symbols as keys.

Although hash2 and hash3 have the same content, hash3 is the simplest writing style.

When used as a hash key, it is recommended to use the symbol because it runs faster.