Bird
0
0

What will this Ruby code print?

medium📝 Predict Output Q5 of 15
Ruby - Functional Patterns in Ruby
What will this Ruby code print?
str = "hello"
str.freeze
puts str.frozen?
ARuntimeError
Bfalse
Ctrue
Dnil
Step-by-Step Solution
Solution:
  1. Step 1: Freeze the string

    Calling freeze on str makes it immutable.
  2. Step 2: Check frozen state

    Calling frozen? returns true if the object is frozen.
  3. Final Answer:

    true -> Option C
  4. Quick Check:

    freeze + frozen? = true [OK]
Quick Trick: Use frozen? to check if object is frozen [OK]
Common Mistakes:
  • Expecting false after freeze
  • Thinking frozen? raises error
  • Confusing frozen? with freeze method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes