puts 5.class puts 'hello'.class puts nil.class
In Ruby, every value is an object. The .class method shows the class of the object. Numbers are Integer, text is String, and nil is an object of class NilClass.
Ruby is designed so that every value is an object. This means all data types are instances of classes, which lets you call methods on any value in a consistent way.
5.upcaseThe method upcase is defined for String objects, not for Integer. Calling it on an integer raises a NoMethodError.
class Animal def speak 'Hello' end end obj = Animal.new puts obj.speak
The Animal class has a method speak that returns 'Hello'. Calling obj.speak prints 'Hello'.
.to_s or .class on literals such as numbers or strings in Ruby?In Ruby, literals like numbers and strings are objects. This means they have methods defined on their classes, so you can call methods like .to_s or .class directly on them.
