Project

General

Profile

Backport #6000 ยป vm_eval.c.respond_to_arity.patch

drbrain (Eric Hodel), 02/11/2012 09:02 AM

View differences:

vm_eval.c (working copy)
274 274
    me = rb_method_entry(klass, idRespond_to);
275 275
    if (me && !(me->flag & NOEX_BASIC)) {
276 276
      VALUE args[2];
277
      int arity = rb_method_entry_arity(me);
278

  
279
      if (arity < 1 || arity > 3) arity = 2;
277 280

  
278 281
      args[0] = ID2SYM(mid);
279 282
      args[1] = Qtrue;
280
	if (!RTEST(vm_call0(th, recv, idRespond_to, 2, args, me))) {
283
	if (!RTEST(vm_call0(th, recv, idRespond_to, arity, args, me))) {
281 284
	    return Qundef;
282 285
	}
283 286
    }
test/ruby/test_object.rb (working copy)
446 446
    assert_equal([[:respond_to?, :to_ary, true]], called, bug5158)
447 447
  end
448 448

  
449
  def test_implicit_respond_to_arity_1
450
    p = Object.new
451

  
452
    called = []
453
    p.singleton_class.class_eval do
454
      define_method(:respond_to?) do |a|
455
        called << [:respond_to?, a]
456
        false
457
      end
458
    end
459
    [[p]].flatten
460
    assert_equal([[:respond_to?, :to_ary]], called, '[bug:6000]')
461
  end
462

  
449 463
  def test_method_missing_passed_block
450 464
    bug5731 = '[ruby-dev:44961]'
451 465