0
0
Rubyprogramming~20 mins

Why hashes are used everywhere in Ruby - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ruby Hash Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Ruby hash code?

Consider this Ruby code snippet:

person = { name: "Alice", age: 30 }
puts person[:name]

What will be printed?

Ruby
person = { name: "Alice", age: 30 }
puts person[:name]
AAlice
B30
Cnil
Dname
Attempts:
2 left
💡 Hint

Look at how the key is accessed using a symbol.

🧠 Conceptual
intermediate
2:00remaining
Why are hashes preferred for method arguments in Ruby?

Why do Ruby programmers often use hashes to pass arguments to methods?

ABecause hashes automatically sort keys alphabetically
BBecause hashes are faster than arrays for all operations
CBecause hashes prevent any changes to the data inside methods
DBecause hashes allow named arguments making code clearer and flexible
Attempts:
2 left
💡 Hint

Think about how named arguments help readability and flexibility.

🔧 Debug
advanced
2:00remaining
Identify the error in this hash usage

What error will this Ruby code produce?

options = { color: "red", size: "medium" }
puts options["color"]
Ruby
options = { color: "red", size: "medium" }
puts options["color"]
Ared
Bnil
CKeyError
DSyntaxError
Attempts:
2 left
💡 Hint

Check the difference between symbol keys and string keys in hashes.

Predict Output
advanced
2:00remaining
What is the output of this nested hash code?

Given this Ruby code:

profile = { user: { name: "Bob", details: { age: 25, city: "NY" } } }
puts profile[:user][:details][:city]

What will it print?

Ruby
profile = { user: { name: "Bob", details: { age: 25, city: "NY" } } }
puts profile[:user][:details][:city]
Anil
Bcity
CNY
DKeyError
Attempts:
2 left
💡 Hint

Follow the keys step by step inside the nested hash.

🧠 Conceptual
expert
3:00remaining
Why are hashes fundamental in Ruby's internal implementation?

Why does Ruby use hashes extensively inside its core and libraries?

ABecause hashes provide fast key-based lookup and flexible data storage
BBecause hashes automatically encrypt data for security
CBecause hashes are immutable and thread-safe by default
DBecause hashes use less memory than arrays in all cases
Attempts:
2 left
💡 Hint

Think about speed and flexibility when storing data with keys.