Bird
0
0

Why does freezing an object in Ruby not guarantee deep immutability of nested objects?

hard📝 Conceptual Q10 of 15
Ruby - Functional Patterns in Ruby
Why does freezing an object in Ruby not guarantee deep immutability of nested objects?
ABecause freeze converts nested objects to strings
BBecause freeze only prevents modifications to the object itself, not its nested objects
CBecause freeze only works on arrays and hashes
DBecause freeze automatically duplicates nested objects
Step-by-Step Solution
Solution:
  1. Step 1: Understand shallow freeze

    freeze makes the object immutable but does not affect nested objects inside it.
  2. Step 2: Nested objects remain mutable

    Nested arrays or hashes inside a frozen object can still be changed unless they are frozen separately.
  3. Final Answer:

    Because freeze only prevents modifications to the object itself, not its nested objects -> Option B
  4. Quick Check:

    freeze is shallow, nested objects stay mutable unless frozen [OK]
Quick Trick: freeze is shallow; freeze nested objects separately for deep immutability [OK]
Common Mistakes:
  • Thinking freeze converts nested objects
  • Assuming freeze duplicates nested objects
  • Believing freeze works only on arrays/hashes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes