Bird
0
0

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

easy📝 Syntax Q12 of 15
Ruby - Functional Patterns in Ruby
Which of the following is the correct way to freeze a string name in Ruby?
Afreeze(name)
Bname.frozen = true
Cname.freeze()
Dfreeze name
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby method call syntax

    In Ruby, to call a method on an object, use dot notation like object.method().
  2. Step 2: Identify the correct freeze syntax

    The correct way to freeze the string name is name.freeze(). Other options are invalid syntax or incorrect usage.
  3. Final Answer:

    name.freeze() -> Option C
  4. Quick Check:

    Method call with dot and parentheses = Correct freeze syntax [OK]
Quick Trick: Use dot notation: object.freeze() to freeze [OK]
Common Mistakes:
  • Using freeze as a standalone function
  • Trying to assign frozen = true
  • Omitting dot before freeze

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes