Bird
0
0

Which of the following is the correct way to freeze a string in Ruby?

easy📝 Syntax Q12 of 15
Ruby - String Operations
Which of the following is the correct way to freeze a string in Ruby?
Astr.freeze = "hello"
Bstr = "hello".freeze
Cfreeze str = "hello"
Dstr = freeze("hello")
Step-by-Step Solution
Solution:
  1. Step 1: Review Ruby freeze syntax

    The correct syntax to freeze a string is to call .freeze on the string object, like "hello".freeze.
  2. Step 2: Check each option

    str = "hello".freeze correctly calls .freeze on the string literal. Options B, C, and D use invalid syntax or incorrect method calls.
  3. Final Answer:

    str = "hello".freeze -> Option B
  4. Quick Check:

    Call .freeze on string = A [OK]
Quick Trick: Use .freeze after the string literal [OK]
Common Mistakes:
MISTAKES
  • Trying to assign freeze as a variable
  • Using freeze as a standalone keyword
  • Calling freeze as a function with parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes