Labs ICT
โญ Pro Login

Everything is an Object

Ruby's pure object-oriented nature.

Everything is an Object

In Ruby, literally everything is an object. Numbers, strings, booleans, arrays, hashes โ€” even classes themselves. This is what makes Ruby so consistent and fun to work with.

42.is_a?(Integer)      # => true
"hello".class          # => String
[1, 2, 3].class        # => Array
true.class             # => TrueClass

You can ask any object about itself. What class is it? What methods does it have?

"hello".method(:upcase)   # => #
42.respond_to?(:odd?)     # => true
3.14.is_a?(Numeric)       # => true

Every object has a unique object_id. Even identical-looking strings have different IDs if they're separate objects in memory:

a = "hello"
b = "hello"

a.object_id == b.object_id  # => false (different objects)
a.equal?(b)                 # => false

You can check exact identity with object_id or the equal? method. == checks value equality, not object identity.

a == b      # => true (same value)
a.equal?(b) # => false (different objects)

Even classes are objects โ€” they're instances of the Class class. This purity means you can pass classes around as arguments, store them in variables, and treat them like any other value.

String.is_a?(Class)    # => true
Class.is_a?(Class)     # => true (meta!)
Try it Yourself ->

๐Ÿงช Quick Quiz

What does everything inherit from in Ruby?