void rb_include_module2(VALUE klass, VALUE orig_klass, VALUE module, bool check, bool add_methods) { if (check) { rb_frozen_class_p(klass); if (!OBJ_TAINTED(klass)) { rb_secure(4); } Check_Type(module, T_MODULE); } // Register the module as included in the class. VALUE ary = rb_attr_get(klass, idIncludedModules); if (ary == Qnil) { ary = rb_ary_new(); rb_ivar_set(klass, idIncludedModules, ary); } else { if (rb_ary_includes(ary, module)) { return; } } rb_ary_insert(ary, 0, module); // Mark the module as included somewhere. const long v = RCLASS_VERSION(module) | RCLASS_IS_INCLUDED; RCLASS_SET_VERSION(module, v); // Register the class as included in the module. ary = rb_attr_get(module, idIncludedInClasses); if (ary == Qnil) { ary = rb_ary_new(); rb_ivar_set(module, idIncludedInClasses, ary); } rb_ary_push(ary, klass); // Delete the ancestors array if it exists, since we just changed it. CFMutableDictionaryRef iv_dict = rb_class_ivar_dict(klass); if (iv_dict != NULL) { CFDictionaryRemoveValue(iv_dict, (const void *)idAncestors); } if (add_methods) { // Copy methods. If original class has the basic -initialize and if the // module has a customized -initialize, we must copy the customized // version to the original class too. rb_vm_copy_methods((Class)module, (Class)klass); // When including into the class Class, also copy the methods to the // singleton class of NSObject. if (klass == rb_cClass || klass == rb_cModule) { rb_vm_copy_methods((Class)module, *(Class *)rb_cNSObject); } if (orig_klass != 0 && orig_klass != klass) { Method m = class_getInstanceMethod((Class)orig_klass, selInitialize); Method m2 = class_getInstanceMethod((Class)klass, selInitialize); if (m != NULL && m2 != NULL && method_getImplementation(m) == (IMP)rb_objc_init && method_getImplementation(m2) != (IMP)rb_objc_init) { rb_vm_copy_method((Class)orig_klass, m2); } } } }
static VALUE node_insert_child(VALUE rcv, SEL sel, VALUE idx, VALUE child) { rb_ary_insert(NODE(rcv)->children, NUM2INT(idx), child); return new_child(rcv, child); }