Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Basics and Runtime
What will be the output of this Ruby code?
str = "hello"
puts str.object_id.class
AObject
BString
CInteger
DNoMethodError
Step-by-Step Solution
Solution:
  1. Step 1: Understand the code

    The code calls object_id on a string, which returns an integer representing the object's unique ID. Then it calls class on that integer.
  2. Step 2: Determine the class of object_id

    Since object_id returns an integer, calling class on it returns Integer.
  3. Final Answer:

    Integer -> Option C
  4. Quick Check:

    object_id returns Integer, so class is Integer [OK]
Quick Trick: object_id returns an Integer object ID [OK]
Common Mistakes:
  • Thinking object_id returns a String
  • Expecting object_id to be an object itself
  • Confusing method chaining results

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes