Bird
0
0

What will this Ruby code print?

medium📝 Predict Output Q5 of 15
Ruby - Classes and Objects
What will this Ruby code print?
puts "Ruby".object_id == "Ruby".object_id
Atrue
Bfalse
Cnil
Derror
Step-by-Step Solution
Solution:
  1. Step 1: Understand object_id for strings

    Each string literal creates a new object with a unique object_id.
  2. Step 2: Compare object_ids of two identical strings

    "Ruby".object_id and another "Ruby".object_id are different, so comparison is false.
  3. Final Answer:

    false -> Option B
  4. Quick Check:

    Different string objects have different object_ids = B [OK]
Quick Trick: Each string literal is a new object with unique id [OK]
Common Mistakes:
  • Assuming identical strings share object_id
  • Expecting true for string equality with object_id
  • Confusing object_id with string content equality

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes