Bird
0
0

What will this Ruby code print?

medium📝 Predict Output Q5 of 15
Ruby - Basics and Runtime
What will this Ruby code print?
num = 42
puts num.is_a?(Object)
Anil
Bfalse
CNoMethodError
Dtrue
Step-by-Step Solution
Solution:
  1. Step 1: Understand is_a? method

    The is_a? method checks if an object is an instance of a class or its subclass.
  2. Step 2: Check if num is an Object

    Since everything in Ruby is an object, num (an integer) is an Object, so num.is_a?(Object) returns true.
  3. Final Answer:

    true -> Option D
  4. Quick Check:

    All values are Objects, so is_a?(Object) = true [OK]
Quick Trick: All Ruby values are Objects, so is_a?(Object) is true [OK]
Common Mistakes:
  • Thinking numbers are not objects
  • Expecting false from is_a?(Object)
  • Confusing is_a? with other methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes