Bird
0
0

Why does merge return a new hash instead of modifying the original hash?

hard📝 Conceptual Q10 of 15
Ruby - Hashes

Why does merge return a new hash instead of modifying the original hash?

ATo keep the original hash unchanged and allow safe merging
BBecause Ruby hashes are immutable
CTo improve performance by avoiding changes
DBecause update method is deprecated
Step-by-Step Solution
Solution:
  1. Step 1: Understand immutability concept in merge

    merge returns a new hash to avoid changing the original, preserving data safety.
  2. Step 2: Eliminate incorrect reasons

    Ruby hashes are mutable, update is not deprecated, and performance is not the main reason.
  3. Final Answer:

    To keep the original hash unchanged and allow safe merging -> Option A
  4. Quick Check:

    merge returns new hash to preserve original [OK]
Quick Trick: merge returns new hash to avoid side effects [OK]
Common Mistakes:
MISTAKES
  • Thinking Ruby hashes are immutable
  • Believing update is deprecated

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes