To clarify, I'm interested in *how*, not *if*, is_a?
determines whether
@my_obj.is_a?(Klass) with no concern for superclasses or modules. I'm
fairly confident it's going to take somebody familiar with
Ruby's source
code, not just the API, to answer this one.
The source code is readily available. Here, from object.c, is the answer
to your question. (Out of curiosity, why are you so curious as to the
internals?)
VALUE
rb_obj_is_kind_of(obj, c)
VALUE obj, c;
{
VALUE cl = CLASS_OF(obj);
switch (TYPE(c)) {
case T_MODULE:
case T_CLASS:
case T_ICLASS:
break;
default:
rb_raise(rb_eTypeError, "class or module required");
}
while (cl) {
if (cl == c || RCLASS(cl)->m_tbl == RCLASS(c)->m_tbl)
return Qtrue;
cl = RCLASS(cl)->super;
}
return Qfalse;
}
···
From: Jon Garvin [mailto:jgarvin.lists@gmail.com]