Hi, > what is instance_method, I can't find the doc for it in programming ruby? > Benoit instance_method is defined in 1.7.2. The return value is an UnboundMethod. Anyway I am sort of wandering why UnboundMethod subclasses Method - it seems to me that it should be the other way around - see the quick patch below - (I did not bother to remove the superflous method definition of umethod_call etc.) /Christoph ------------ --- eval.c.new Thu Dec 20 16:35:28 2001 +++ eval.c.old Thu Dec 20 14:10:50 2001 @@ -6686,7 +6686,7 @@ } static VALUE -umethod_eq(method, other) +method_eq(method, other) VALUE method, other; { struct METHOD *m1, *m2; @@ -6750,7 +6750,7 @@ } static VALUE -umethod_clone(self) +method_clone(self) VALUE self; { VALUE clone; @@ -6792,13 +6792,6 @@ } static VALUE -method_bind(method, recv) - VALUE method, recv; -{ - umethod_bind(method_unbind(method),recv); -}; - -static VALUE umethod_call(argc, argv, method) int argc; VALUE *argv; @@ -6839,7 +6832,7 @@ } static VALUE -umethod_arity(method) +method_arity(method) VALUE method; { struct METHOD *data; @@ -6872,7 +6865,7 @@ } static VALUE -umethod_inspect(method) +method_inspect(method) VALUE method; { struct METHOD *data; @@ -6959,7 +6952,7 @@ else if (argc == 2) { id = rb_to_id(argv[0]); body = argv[1]; - if (rb_obj_is_kind_of(body, rb_cUnboundMethod)) { + if (rb_obj_is_kind_of(body, rb_cMethod)) { body = method_proc(body); } else if (!rb_obj_is_proc(body)) { @@ -7029,29 +7022,27 @@ rb_undef_method(CLASS_OF(rb_cBinding), "new"); rb_define_method(rb_cBinding, "clone", bind_clone, 0); - - rb_cUnboundMethod = rb_define_class("UnboundMethod", rb_cObject); - rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1); - rb_define_method(rb_cModule, "instance_method", rb_mod_method, 1); - rb_undef_method(CLASS_OF(rb_cUnboundMethod), "allocate"); - rb_undef_method(CLASS_OF(rb_cUnboundMethod), "new"); - rb_define_method(rb_cUnboundMethod, "==", umethod_eq, 1); - rb_define_method(rb_cUnboundMethod, "clone", umethod_clone, 0); - rb_define_method(rb_cUnboundMethod, "arity", umethod_arity, 0); - rb_define_method(rb_cUnboundMethod, "inspect", umethod_inspect, 0); - rb_define_method(rb_cUnboundMethod, "to_s", umethod_inspect, 0); - - - rb_cMethod = rb_define_class("Method", rb_cUnboundMethod); - rb_define_method(rb_cMethod, "call", method_call, -1); + rb_cMethod = rb_define_class("Method", rb_cObject); + rb_undef_method(CLASS_OF(rb_cMethod), "allocate"); + rb_undef_method(CLASS_OF(rb_cMethod), "new"); + rb_define_method(rb_cMethod, "==", method_eq, 1); + rb_define_method(rb_cMethod, "clone", method_clone, 0); + rb_define_method(rb_cMethod, "call", method_call, -1); rb_define_method(rb_cMethod, "[]", method_call, -1); + rb_define_method(rb_cMethod, "arity", method_arity, 0); + rb_define_method(rb_cMethod, "inspect", method_inspect, 0); + rb_define_method(rb_cMethod, "to_s", method_inspect, 0); rb_define_method(rb_cMethod, "to_proc", method_proc, 0); rb_define_method(rb_cMethod, "unbind", method_unbind, 0); - rb_define_method(rb_cMethod, "bind", method_bind, 1); - rb_define_method(rb_mKernel, "method", rb_obj_method, 1); - + rb_cUnboundMethod = rb_define_class("UnboundMethod", rb_cMethod); + rb_define_method(rb_cUnboundMethod, "call", umethod_call, -1); + rb_define_method(rb_cUnboundMethod, "[]", umethod_call, -1); + rb_define_method(rb_cUnboundMethod, "to_proc", umethod_proc, 0); + rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1); + rb_define_method(rb_cUnboundMethod, "unbind", umethod_unbind, 0); + rb_define_method(rb_cModule, "instance_method", rb_mod_method, 1); } static VALUE rb_eThreadError;