Object#kind_of?

obj.kind_of?(klass) -> true or false
Returns: boolean · Updated March 13, 2026 · Core Classes
types class object checking

kind_of? is a Kernel method that checks whether an object is an instance of a given class or any of its ancestor classes. It’s functionally identical to is_a? — the two are aliases, and the choice between them is purely stylistic.

Syntax

obj.kind_of?(klass)

Parameters

ParameterTypeDescription
klassClass or ModuleThe class or module to check against

Examples

Basic type checking

"hello".kind_of?(String)
# => true

"hello".kind_of?(Object)
# => true (String is a subclass of Object)

"hello".kind_of?(Integer)
# => false

Checking superclasses

42.kind_of?(Integer)
# => true

42.kind_of?(Numeric)
# => true (Numeric is a superclass of Integer)

42.kind_of?(Object)
# => true (Object is the root class)

Checking included modules

[1, 2, 3].kind_of?(Enumerable)
# => true

When to use kind_of? vs is_a?

There’s no functional difference. Use whichever reads better in context:

# Both are equivalent:
item.is_a?(String)
item.kind_of?(String)

Some developers prefer is_a? for type checking (reading as “is a string”) and kind_of? when emphasizing the class hierarchy (reading as “kind of string”). Pick one and be consistent.

Common Patterns

Guard clauses

def process(data)
  return unless data.kind_of?(Hash)
  # ...
end

Case statements

case object
when String then object.upcase
when Array then object.join
end

Errors

Passing a non-Class raises TypeError:

"test".kind_of?("string")
# => TypeError: class or module required

See Also