End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Object#instance_of?
obj.instance_of?(class) → true or false
object.c
View on GitHub ↗
VALUE
rb_obj_is_instance_of(VALUE obj, VALUE c)
{
c = class_or_module_required(c);
if (rb_obj_class(obj) == c) return Qtrue;
return Qfalse;
}
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
See also
#inspect
#instance_variable_defined?
#hash
#instance_variable_get
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1