Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Object#instance_of?

(::Module | ::Class module_or_class) -> bool
obj.instance_of?(class) → true or false

Returns true if obj is an instance of the given class. See also Object#kind_of?.

Example
class A;     end
class B < A; end
class C < B; end

b = B.new
b.instance_of? A   #=> false
b.instance_of? B   #=> true
b.instance_of? C   #=> false