Skip to content
Justice Tech School

Everything is an Object

Even numbers and nil are objects with methods. object_id, class, nil?, respond_to?, methods and instance_of? let you inspect them.

Example
puts 5.class, 5.respond_to?(:+), nil.to_a.inspect
puts "a".object_id == "a".object_id
puts :a.object_id == :a.object_id
puts 3.14.instance_of?(Float)

Result

Integer
true
[]
false
true
true

Exercise

Class of 5.

5.

Quiz Test

Are numbers objects in Ruby?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.