Bird
0
0

What does the .class method return when called on an object in Ruby?

easy📝 Conceptual Q11 of 15
Ruby - Variables and Data Types
What does the .class method return when called on an object in Ruby?
AWhether the object is a kind of a class
BThe exact type (class) of the object
CThe parent class of the object
DA boolean indicating if the object is a class
Step-by-Step Solution
Solution:
  1. Step 1: Understand what .class does

    The .class method returns the exact class of the object it is called on.
  2. Step 2: Compare with other options

    Options A, C, and D describe behaviors of other methods or incorrect meanings.
  3. Final Answer:

    The exact type (class) of the object -> Option B
  4. Quick Check:

    .class returns exact type [OK]
Quick Trick: Remember: .class gives exact type, not inheritance [OK]
Common Mistakes:
MISTAKES
  • Confusing .class with .is_a?
  • Thinking .class returns boolean
  • Assuming .class returns parent class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes