Bird
0
0

What happens if you try to modify a frozen object in Ruby?

easy📝 Conceptual Q1 of 15
Ruby - Functional Patterns in Ruby
What happens if you try to modify a frozen object in Ruby?
AIt raises a RuntimeError
BIt silently ignores the modification
CIt creates a new object with the modification
DIt converts the object to a string
Step-by-Step Solution
Solution:
  1. Step 1: Understand the effect of freeze

    Freezing an object in Ruby makes it immutable, so any modification attempt is disallowed.
  2. Step 2: Behavior on modification attempt

    Trying to change a frozen object raises a RuntimeError to prevent changes.
  3. Final Answer:

    It raises a RuntimeError -> Option A
  4. Quick Check:

    freeze + modify = RuntimeError [OK]
Quick Trick: Frozen objects raise errors on modification attempts [OK]
Common Mistakes:
  • Assuming modification silently fails
  • Thinking freeze creates a copy
  • Believing freeze converts object type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes