Bird
0
0

How does Ruby handle reassigning a constant during runtime?

hard📝 Application Q9 of 15
Ruby - Basics and Runtime
How does Ruby handle reassigning a constant during runtime?
MY_CONST = 10
MY_CONST = 20
puts MY_CONST
ARuby crashes with runtime error
BRuby warns but allows reassignment; outputs 20
CRuby ignores reassignment; outputs 10
DRuby raises a syntax error and stops
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby constants behavior

    Ruby allows constants to be reassigned but issues a warning.
  2. Step 2: Check output after reassignment

    The value changes to 20 and puts prints 20.
  3. Final Answer:

    Ruby warns but allows reassignment; outputs 20 -> Option B
  4. Quick Check:

    Constants warn on reassignment but update value [OK]
Quick Trick: Constants warn but can be changed at runtime [OK]
Common Mistakes:
  • Expecting syntax or runtime error
  • Thinking constants are immutable
  • Assuming reassignment is ignored

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes