Bird
0
0

In Ruby, why can you call methods on numbers like 5 or 10?

easy📝 Conceptual Q1 of 15
Ruby - Classes and Objects
In Ruby, why can you call methods on numbers like 5 or 10?
ABecause methods are only for strings in Ruby
BBecause numbers are primitive types without methods
CBecause numbers are objects with methods attached
DBecause Ruby converts numbers to strings first
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby's object model

    In Ruby, everything is an object, including numbers, so they have methods.
  2. Step 2: Apply this to numbers

    Since numbers are objects, you can call methods directly on them like 5.to_s or 10.next.
  3. Final Answer:

    Because numbers are objects with methods attached -> Option C
  4. Quick Check:

    Everything is an object = D [OK]
Quick Trick: Remember: In Ruby, all data types are objects [OK]
Common Mistakes:
  • Thinking numbers are primitive types without methods
  • Assuming methods only belong to strings
  • Believing Ruby converts numbers to strings automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes