Bird
0
0

What will be the output of the following Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Basics and Runtime
What will be the output of the following Ruby code?
num = 10
puts num.class
AInteger
BFixnum
CNumeric
DObject
Step-by-Step Solution
Solution:
  1. Step 1: Understand the class method

    The class method returns the class of the object it is called on.
  2. Step 2: Identify the class of the number 10 in Ruby 3.12+

    In modern Ruby versions, integers are instances of the Integer class (Fixnum and Bignum were unified).
  3. Final Answer:

    Integer -> Option A
  4. Quick Check:

    10.class = Integer [OK]
Quick Trick: Use .class to find an object's type in Ruby [OK]
Common Mistakes:
  • Choosing Fixnum (old Ruby versions)
  • Confusing Numeric with Integer
  • Thinking class returns Object always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes