Project

General

Profile

Feature #7836 ยป 0001-proc.c-include-prepended-method-flag.patch

nobu (Nobuyoshi Nakada), 03/05/2013 08:32 PM

View differences:

proc.c
1308 1308
 */
1309 1309

  
1310 1310
static VALUE
1311
rb_mod_instance_method(VALUE mod, VALUE vid)
1311
rb_mod_instance_method(int argc, VALUE *argv, VALUE mod)
1312 1312
{
1313
    VALUE vid = (rb_check_arity(argc, 1, 2), argv[0]);
1314
    int prepended = argc == 1 || RTEST(argv[1]);
1313 1315
    ID id = rb_check_id(&vid);
1314 1316
    if (!id) {
1315 1317
	rb_method_name_error(mod, vid);
1316 1318
    }
1319
    if (!prepended) mod = RCLASS_ORIGIN(mod);
1317 1320
    return mnew(mod, Qundef, id, rb_cUnboundMethod, FALSE);
1318 1321
}
1319 1322

  
......
1325 1328
 */
1326 1329

  
1327 1330
static VALUE
1328
rb_mod_public_instance_method(VALUE mod, VALUE vid)
1331
rb_mod_public_instance_method(int argc, VALUE *argv, VALUE mod)
1329 1332
{
1333
    VALUE vid = (rb_check_arity(argc, 1, 2), argv[0]);
1334
    int prepended = argc == 1 || RTEST(argv[1]);
1330 1335
    ID id = rb_check_id(&vid);
1331 1336
    if (!id) {
1332 1337
	rb_method_name_error(mod, vid);
1333 1338
    }
1339
    if (!prepended) mod = RCLASS_ORIGIN(mod);
1334 1340
    return mnew(mod, Qundef, id, rb_cUnboundMethod, TRUE);
1335 1341
}
1336 1342

  
......
2390 2396
    rb_define_method(rb_cUnboundMethod, "parameters", rb_method_parameters, 0);
2391 2397

  
2392 2398
    /* Module#*_method */
2393
    rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, 1);
2394
    rb_define_method(rb_cModule, "public_instance_method", rb_mod_public_instance_method, 1);
2399
    rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, -1);
2400
    rb_define_method(rb_cModule, "public_instance_method", rb_mod_public_instance_method, -1);
2395 2401
    rb_define_private_method(rb_cModule, "define_method", rb_mod_define_method, -1);
2396 2402

  
2397 2403
    /* Kernel */
test/ruby/test_method.rb
549 549
  end
550 550

  
551 551
  def test_prepended
552
    bug7836 = '[ruby-core:52160] [Bug #7836]'
552
    feature7836 = '[ruby-core:52160] [Feature #7836]'
553 553
    bug7988 = '[ruby-core:53038] [Bug #7988]'
554 554
    m = Module.new {
555 555
      def foo
556 556
      end
557
      def zot
558
      end
557 559
    }
558 560
    c = Class.new {
559 561
      def foo
......
561 563
      prepend m
562 564
    }
563 565
    assert_raise(NameError, bug7988) {Module.new{prepend m}.instance_method(:bar)}
566
    assert_equal(m, c.instance_method(:foo).owner, feature7836)
567
    assert_equal(m, c.instance_method(:foo, true).owner, feature7836)
568
    assert_equal(c, c.instance_method(:foo, false).owner, feature7836)
569
    assert_raise(NameError, feature7836) {c.instance_method(:zot, false)}
564 570
  end
565 571

  
566 572
  def test_gced_bmethod