Bird
0
0

What is a key advantage of using hashes in Ruby compared to arrays?

easy📝 Conceptual Q2 of 15
Ruby - Hashes
What is a key advantage of using hashes in Ruby compared to arrays?
AHashes maintain order of elements by default
BHashes cannot store multiple data types
CHashes use numeric indexes only
DHashes allow accessing elements by descriptive keys
Step-by-Step Solution
Solution:
  1. Step 1: Identify how hashes access data

    Hashes use keys, often descriptive symbols or strings, to access values directly.
  2. Step 2: Contrast with arrays

    Arrays use numeric indexes, which are less descriptive and can be harder to manage for related data.
  3. Final Answer:

    Hashes allow accessing elements by descriptive keys -> Option D
  4. Quick Check:

    Hashes use keys for access = D [OK]
Quick Trick: Hashes use keys, arrays use numeric indexes [OK]
Common Mistakes:
  • Assuming hashes use numeric indexes
  • Believing hashes cannot store mixed data types
  • Thinking hashes always maintain insertion order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes