Bird
0
0

Which of the following is the correct syntax to check if variable obj is a kind of Array in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Inheritance
Which of the following is the correct syntax to check if variable obj is a kind of Array in Ruby?
Aobj.is_a(Array)
Bobj.kind_of?(Array)
Cobj.kind_of(Array)
Dobj.is_a?[Array]
Step-by-Step Solution
Solution:
  1. Step 1: Recall method syntax

    Both is_a? and kind_of? require a question mark and parentheses around the class name.
  2. Step 2: Check each option

    obj.kind_of?(Array) uses correct method name and syntax. Options B and C miss the question mark, and D has incorrect bracket usage.
  3. Final Answer:

    obj.kind_of?(Array) -> Option B
  4. Quick Check:

    Correct method syntax includes ? and parentheses [OK]
Quick Trick: Use method? with parentheses: obj.kind_of?(Class) [OK]
Common Mistakes:
  • Omitting the question mark in method name
  • Using square brackets instead of parentheses
  • Confusing is_a and kind_of syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes