Recall & Review
beginner
What is a hash in Ruby?
A hash is a collection of key-value pairs, like a dictionary, where you can look up a value using its key.
Click to reveal answer
beginner
How do you create a hash with symbol keys in Ruby?
You can create it using curly braces and symbol keys with colons, like:
{ name: "Alice", age: 30 }.Click to reveal answer
beginner
How do you create a hash with string keys in Ruby?
Use curly braces with strings as keys and hash rockets, like:
{ "name" => "Alice", "age" => 30 }.Click to reveal answer
intermediate
What is the difference between symbol keys and string keys in Ruby hashes?
Symbol keys are immutable and often faster, while string keys are mutable. Symbols are written without quotes and strings with quotes.
Click to reveal answer
intermediate
Show an example of a Ruby hash mixing symbol and string keys.
Example:
{ name: "Alice", "age" => 30 }. You can mix keys but be careful when accessing values.Click to reveal answer
Which of these is a valid Ruby hash with symbol keys?
✗ Incorrect
Option A uses symbol keys with colons inside curly braces, which is the correct syntax for symbol-key hashes.
How do you access the value for key :name in hash
{ name: "Eve" }?✗ Incorrect
You access symbol keys using the symbol itself inside square brackets, like
hash[:name].Which symbol key is equivalent to the string key "age" in a Ruby hash?
✗ Incorrect
The symbol :age is a different type from the string "age" but often used as a key in hashes.
What happens if you mix symbol and string keys in a Ruby hash?
✗ Incorrect
Symbol and string keys are different objects, so they are treated as different keys in a hash.
Which syntax creates a hash with string keys?
✗ Incorrect
Using strings as keys requires the hash rocket => syntax inside curly braces.
Explain how to create a Ruby hash using symbol keys and how to access its values.
Think about keys without quotes and how you get values.
You got /3 concepts.
Describe the difference between using string keys and symbol keys in Ruby hashes.
Consider how keys look and behave.
You got /4 concepts.