static mrb_value mrb_module_instance_method(mrb_state *mrb, mrb_value self) { struct RClass *owner; struct RProc *proc; struct RObject *ume; mrb_sym name; mrb_get_args(mrb, "n", &name); mrb_search_method_owner(mrb, mrb_class_ptr(self), self, name, &owner, &proc, TRUE); ume = method_object_alloc(mrb, mrb_class_get(mrb, "UnboundMethod")); mrb_obj_iv_set(mrb, ume, mrb_intern_lit(mrb, "@owner"), mrb_obj_value(owner)); mrb_obj_iv_set(mrb, ume, mrb_intern_lit(mrb, "@recv"), mrb_nil_value()); mrb_obj_iv_set(mrb, ume, mrb_intern_lit(mrb, "@name"), mrb_symbol_value(name)); mrb_obj_iv_set(mrb, ume, mrb_intern_lit(mrb, "proc"), proc ? mrb_obj_value(proc) : mrb_nil_value()); mrb_obj_iv_set(mrb, ume, mrb_intern_lit(mrb, "@klass"), self); return mrb_obj_value(ume); }
static mrb_value mrb_kernel_method(mrb_state *mrb, mrb_value self) { struct RClass *owner; struct RProc *proc; struct RObject *me; mrb_sym name; mrb_get_args(mrb, "n", &name); mrb_search_method_owner(mrb, mrb_class(mrb, self), self, name, &owner, &proc, FALSE); me = method_object_alloc(mrb, mrb_class_get(mrb, "Method")); mrb_obj_iv_set(mrb, me, mrb_intern_lit(mrb, "@owner"), mrb_obj_value(owner)); mrb_obj_iv_set(mrb, me, mrb_intern_lit(mrb, "@recv"), self); mrb_obj_iv_set(mrb, me, mrb_intern_lit(mrb, "@name"), mrb_symbol_value(name)); mrb_obj_iv_set(mrb, me, mrb_intern_lit(mrb, "proc"), proc ? mrb_obj_value(proc) : mrb_nil_value()); mrb_obj_iv_set(mrb, me, mrb_intern_lit(mrb, "@klass"), mrb_obj_value(mrb_class(mrb, self))); return mrb_obj_value(me); }
static mrb_value mrb_module_instance_method(mrb_state *mrb, mrb_value self) { struct RClass *unbound_method = mrb_class_get(mrb, "UnboundMethod"); struct RClass *owner; struct RProc *proc; mrb_value id; mrb_value ume; mrb_value argv[4]; mrb_get_args(mrb, "o", &id); mrb_search_method_owner(mrb, mrb_class_ptr(self), self, id, &owner, &proc); argv[0] = self; argv[1] = mrb_obj_value(owner); argv[2] = id; argv[3] = mrb_obj_value(proc); ume = mrb_obj_new(mrb, unbound_method, 4, argv); return ume; }
static mrb_value mrb_kernel_method(mrb_state *mrb, mrb_value self) { struct RClass *method = mrb_class_get(mrb, "Method"); struct RClass *owner; struct RProc *proc; mrb_value id; mrb_value me; mrb_value argv[5]; mrb_get_args(mrb, "o", &id); mrb_search_method_owner(mrb, mrb_class(mrb, self), self, id, &owner, &proc); argv[0] = mrb_obj_value(mrb_obj_class(mrb, self)); argv[1] = mrb_obj_value(owner); argv[2] = self; argv[3] = id; argv[4] = mrb_obj_value(proc); me = mrb_obj_new(mrb, method, 5, argv); return me; }