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
object.c
View on GitHub ↗
VALUE
rb_obj_is_instance_of(VALUE obj, VALUE c)
{
c = class_or_module_required(c);
return RBOOL(rb_obj_class(obj) == c);
}
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.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0