All original content is created in Ukrainian. Not all content has been translated yet. Some posts may only be available in Ukrainian.Learn more

is_a?, kind_of?, instance_of? — how does Ruby check the type of an object?

Post cover: is_a?, kind_of?, instance_of? — how does Ruby check the type of an object?
Table of contentsClick link to navigate to the desired location
This content has been automatically translated from Ukrainian.
is_a?, kind_of?, and instance_of? in Ruby check the type of an object, but with different depths.

is_a? and kind_of?

They are equivalent - both check if the object is an instance of a certain class or its descendant.
class Animal; end
class Dog < Animal; end

dog = Dog.new

dog.is_a?(Dog)      # true
dog.is_a?(Animal)   # true - because Dog < Animal
dog.kind_of?(Animal) # true - the same

instance_of?

Checks the exact class, without inheritance.
dog.instance_of?(Dog)     # true
dog.instance_of?(Animal)  # false — because it is a descendant, not the class itself
In short:
is_a? and kind_of? - check through the inheritance chain
instance_of? - checks only the specific class

This post doesn't have any additions from the author yet.

What happens if you call [1, 2, 3].map(&Person)
Oct 29, '25 17:54

What happens if you call [1, 2, 3].map(&Person)

Нотатки про Ruby та RoR
Singleton class (eigenclass) in Ruby: what it is and why it is needed
Oct 29, '25 18:29

Singleton class (eigenclass) in Ruby: what it is and why it is needed

Нотатки про Ruby та RoR
==, equal?, eql?, === in Ruby: what they check and when to use them
Oct 29, '25 20:47

==, equal?, eql?, === in Ruby: what they check and when to use them

Нотатки про Ruby та RoR
Include, Extend, Prepend in Ruby: how they work and what the difference is
Oct 29, '25 21:20

Include, Extend, Prepend in Ruby: how they work and what the difference is

Нотатки про Ruby та RoR
module_function in Ruby: when module methods are available as module methods and as functions
Oct 29, '25 21:53

module_function in Ruby: when module methods are available as module methods and as functions

Нотатки про Ruby та RoR
What is memoization in Ruby?
Oct 30, '25 10:17

What is memoization in Ruby?

Нотатки про Ruby та RoR
&& vs and — the difference in Ruby that can break your code
Oct 30, '25 20:23

&& vs and — the difference in Ruby that can break your code

Нотатки про Ruby та RoR
Variables in Ruby: @, @@ and class instance variable
Oct 30, '25 20:54

Variables in Ruby: @, @@ and class instance variable

Нотатки про Ruby та RoR
The difference between blank?, present?, empty? and nil? in Ruby
Oct 30, '25 21:06

The difference between blank?, present?, empty? and nil? in Ruby

Нотатки про Ruby та RoR
What is Middleware in Ruby on Rails and when is it used
Nov 4, '25 10:39

What is Middleware in Ruby on Rails and when is it used

Нотатки про Ruby та RoR
What is the Vanilla Rails approach?
Nov 14, '25 16:48

What is the Vanilla Rails approach?

Нотатки про Ruby та RoR
What is Elasticsearch and how does it work?
Nov 22, '25 12:35

What is Elasticsearch and how does it work?

Нотатки про Ruby та RoR