End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Object#is_a?
obj.is_a?(class) → true or false
object.c
View on GitHub ↗
VALUE
rb_obj_is_kind_of(VALUE obj, VALUE c)
{
VALUE cl = CLASS_OF(obj);
// Note: YJIT needs this function to never allocate and never raise when
// `c` is a class or a module.
c = class_or_module_required(c);
return RBOOL(class_search_ancestor(cl, RCLASS_ORIGIN(c)));
}
Alias of #kind_of?
Returns true if class is the class of obj, or if class is one of the superclasses of obj or modules included in obj.
Example
module M; end class A include M end class B < A; end class C < B; end b = B.new b.is_a? A #=> true b.is_a? B #=> true b.is_a? C #=> false b.is_a? M #=> true b.kind_of? A #=> true b.kind_of? B #=> true b.kind_of? C #=> false b.kind_of? M #=> true
See also
#kind_of?
#instance_variable_set
#itself
#instance_variables
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0