Ruby - Classes and ObjectsIn Ruby, why can you call methods on numbers like 5 or 10?ABecause methods are only for strings in RubyBBecause numbers are primitive types without methodsCBecause numbers are objects with methods attachedDBecause Ruby converts numbers to strings firstCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand Ruby's object modelIn Ruby, everything is an object, including numbers, so they have methods.Step 2: Apply this to numbersSince numbers are objects, you can call methods directly on them like 5.to_s or 10.next.Final Answer:Because numbers are objects with methods attached -> Option CQuick 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 methodsAssuming methods only belong to stringsBelieving Ruby converts numbers to strings automatically
Master "Classes and Objects" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Blocks, Procs, and Lambdas - Block syntax (do..end and curly braces) - Quiz 10hard Blocks, Procs, and Lambdas - Why blocks are fundamental to Ruby - Quiz 12easy Blocks, Procs, and Lambdas - Block given? check - Quiz 3easy Class Methods and Variables - Object#dup and Object#clone - Quiz 6medium Classes and Objects - Attr_reader, attr_writer, attr_accessor - Quiz 2easy Enumerable and Collection Processing - Zip for combining arrays - Quiz 12easy Enumerable and Collection Processing - Sort_by for custom sorting - Quiz 5medium Enumerable and Collection Processing - Sort_by for custom sorting - Quiz 10hard Error Handling - Exception hierarchy - Quiz 11easy Modules and Mixins - Custom modules as mixins - Quiz 6medium