If you trace through source 1.9.3, you will find what is defined?implemented in insns.def:
DEFINE_INSN
defined
(rb_num_t op_type, VALUE obj, VALUE needstr)
switch (type) {
case DEFINED_CONST:
klass = v;
if (vm_get_ev_const(th, GET_ISEQ(), klass, SYM2ID(obj), 1)) {
expr_type = "constant";
}
break;
So, when you defined? SomeConstant, you seep through this big one switchand end up calling vm_get_ev_const. The function is defined in vm_insnhelper.c:
static inline VALUE
vm_get_ev_const(rb_thread_t *th, const rb_iseq_t *iseq,
VALUE orig_klass, ID id, int is_defined)
, . , vm_get_ev_const rb_const_defined rb_const_defined_from, C, ; klass.
Object.const_defined?. , " " , A::B, Object.const_defined? :A && A.const_defined? :B, Object.const_defined? :'A::B' . . , , , , Object.const_defined? .