puts 42.class puts "hello".class puts :symbol.class
In Ruby 2.4 and later, Fixnum and Bignum are unified into Integer. So 42.class returns Integer. Strings and symbols have their own classes: String and Symbol.
In Ruby, everything is an object. This means numbers, strings, classes, and even nil are objects. You can call methods on all of them.
5.upcaseThe method 'upcase' is defined for String objects, not for Integer objects. Since 5 is an Integer, calling 5.upcase raises NoMethodError.
puts Class.class puts Integer.class puts 10.class.class
In Ruby, Class is an object of class Class. Integer is a class, so its class is Class. The class of 10 is Integer, and Integer's class is Class.
obj = "42" def obj.description "The number is #{self}" end puts obj.description puts 42.respond_to?(:description)
The singleton method 'description' is defined on the object referenced by 'obj', which is the string "42". The method is defined on the specific object 'obj' references, but 42 literals elsewhere do not have it. So 'obj.description' works, but '42.respond_to?(:description)' returns false because the literal 42 is a different object.