Bird
0
0

Which Ruby method returns a new hash by combining two hashes without changing the original?

easy📝 Conceptual Q11 of 15
Ruby - Hashes

Which Ruby method returns a new hash by combining two hashes without changing the original?

A<code>merge</code>
B<code>merge!</code>
C<code>update</code>
D<code>replace</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand merge behavior

    merge returns a new hash combining two hashes without modifying the original.
  2. Step 2: Compare with merge! and update

    Both merge! and update modify the original hash, so they don't return a new one.
  3. Final Answer:

    merge -> Option A
  4. Quick Check:

    merge returns new hash [OK]
Quick Trick: Remember: merge returns new hash, merge! updates original [OK]
Common Mistakes:
  • Confusing merge and merge! methods
  • Thinking update returns a new hash
  • Assuming replace merges hashes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes