Bird
0
0

Which of the following is the correct way to check the class of an object obj in Ruby?

easy📝 Syntax Q3 of 15
Ruby - Basics and Runtime
Which of the following is the correct way to check the class of an object obj in Ruby?
Aobj.type
Bobj.class
Cclass(obj)
Dobj.get_class()
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby syntax for class checking

    In Ruby, to find the class of an object, you call the method class on it like obj.class.
  2. Step 2: Check each option

    Only obj.class uses the correct Ruby syntax. The others are invalid or not Ruby methods.
  3. Final Answer:

    obj.class -> Option B
  4. Quick Check:

    Check class with obj.class [OK]
Quick Trick: Use .class method to find an object's class [OK]
Common Mistakes:
MISTAKES
  • Using non-existent methods like type or get_class
  • Trying to call class as a function
  • Confusing syntax from other languages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes