Complete the code to create a hash with a key 'name' and value 'Ruby'.
person = { :name => [1] }In Ruby, hash values can be strings. Here, the value for the key :name is the string "Ruby".
Complete the code to access the value of the key :age from the hash.
person = { age: 25 }
age = person[[1]]To access a value in a Ruby hash using a symbol key, use the symbol :age inside the brackets.
Fix the error in the code to add a new key-value pair :city => 'Tokyo' to the hash.
person = { name: "Ruby" }
person[1] = "Tokyo"To add or update a key-value pair in a Ruby hash, use the syntax hash[:key] = value.
Fill both blanks to create a hash with keys :a and :b and values 1 and 2.
numbers = { [1]: 1, [2]: 2 }Keys in Ruby hashes can be symbols written as :a and :b. Here, we use the shorthand syntax with keys a and b.
Fill all three blanks to create a hash with keys :x, :y and values 10, 20, and access the value of :y.
coords = { [1]: [2], [3]: 20 }
y_value = coords[:y]The hash has keys :x and :y with values 10 and 20. We access the value of :y using coords[:y].