Bird
0
0

What does the merge method do when called on a Ruby hash?

easy📝 Conceptual Q1 of 15
Ruby - Hashes

What does the merge method do when called on a Ruby hash?

AReturns a new hash combining two hashes without modifying the original
BModifies the original hash by adding new keys only
CDeletes keys from the original hash
DReturns the keys of the hash as an array
Step-by-Step Solution
Solution:
  1. Step 1: Understand the behavior of merge

    The merge method combines two hashes and returns a new hash without changing the original.
  2. Step 2: Compare with other options

    Options B, C, and D describe different behaviors not related to merge.
  3. Final Answer:

    Returns a new hash combining two hashes without modifying the original -> Option A
  4. Quick Check:

    merge method = returns new combined hash [OK]
Quick Trick: merge returns new hash, update modifies original [OK]
Common Mistakes:
  • Confusing merge with update
  • Thinking merge modifies original hash

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes