Feature #7836 ยป 0001-proc.c-include-prepended-method-flag.patch
| proc.c | ||
|---|---|---|
|  */ | ||
| static VALUE | ||
| rb_mod_instance_method(VALUE mod, VALUE vid) | ||
| rb_mod_instance_method(int argc, VALUE *argv, VALUE mod) | ||
| { | ||
|     VALUE vid = (rb_check_arity(argc, 1, 2), argv[0]); | ||
|     int prepended = argc == 1 || RTEST(argv[1]); | ||
|     ID id = rb_check_id(&vid); | ||
|     if (!id) { | ||
| 	rb_method_name_error(mod, vid); | ||
|     } | ||
|     if (!prepended) mod = RCLASS_ORIGIN(mod); | ||
|     return mnew(mod, Qundef, id, rb_cUnboundMethod, FALSE); | ||
| } | ||
| ... | ... | |
|  */ | ||
| static VALUE | ||
| rb_mod_public_instance_method(VALUE mod, VALUE vid) | ||
| rb_mod_public_instance_method(int argc, VALUE *argv, VALUE mod) | ||
| { | ||
|     VALUE vid = (rb_check_arity(argc, 1, 2), argv[0]); | ||
|     int prepended = argc == 1 || RTEST(argv[1]); | ||
|     ID id = rb_check_id(&vid); | ||
|     if (!id) { | ||
| 	rb_method_name_error(mod, vid); | ||
|     } | ||
|     if (!prepended) mod = RCLASS_ORIGIN(mod); | ||
|     return mnew(mod, Qundef, id, rb_cUnboundMethod, TRUE); | ||
| } | ||
| ... | ... | |
|     rb_define_method(rb_cUnboundMethod, "parameters", rb_method_parameters, 0); | ||
|     /* Module#*_method */ | ||
|     rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, 1); | ||
|     rb_define_method(rb_cModule, "public_instance_method", rb_mod_public_instance_method, 1); | ||
|     rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, -1); | ||
|     rb_define_method(rb_cModule, "public_instance_method", rb_mod_public_instance_method, -1); | ||
|     rb_define_private_method(rb_cModule, "define_method", rb_mod_define_method, -1); | ||
|     /* Kernel */ | ||
| test/ruby/test_method.rb | ||
|---|---|---|
|   end | ||
|   def test_prepended | ||
|     bug7836 = '[ruby-core:52160] [Bug #7836]' | ||
|     feature7836 = '[ruby-core:52160] [Feature #7836]' | ||
|     bug7988 = '[ruby-core:53038] [Bug #7988]' | ||
|     m = Module.new { | ||
|       def foo | ||
|       end | ||
|       def zot | ||
|       end | ||
|     } | ||
|     c = Class.new { | ||
|       def foo | ||
| ... | ... | |
|       prepend m | ||
|     } | ||
|     assert_raise(NameError, bug7988) {Module.new{prepend m}.instance_method(:bar)} | ||
|     assert_equal(m, c.instance_method(:foo).owner, feature7836) | ||
|     assert_equal(m, c.instance_method(:foo, true).owner, feature7836) | ||
|     assert_equal(c, c.instance_method(:foo, false).owner, feature7836) | ||
|     assert_raise(NameError, feature7836) {c.instance_method(:zot, false)} | ||
|   end | ||
|   def test_gced_bmethod | ||