Project

General

Profile

Feature #9783 ยป 0001-Implement-Method-curry-which-delegates-to-to_proc.cu.patch

plexus (Arne Brasseur), 04/29/2014 05:39 AM

View differences:

proc.c
1804 1804
}
1805 1805

  
1806 1806
VALUE
1807
rb_method_curry(int argc, VALUE *argv, VALUE self)
1808
{
1809
    VALUE proc = rb_funcall(self, rb_intern("to_proc"), 0);
1810
    return rb_funcall2(proc, rb_intern("curry"), argc, argv);
1811
}
1812

  
1813
VALUE
1807 1814
rb_method_call_with_block(int argc, VALUE *argv, VALUE method, VALUE pass_procval)
1808 1815
{
1809 1816
    VALUE result = Qnil;	/* OK */
......
2632 2639
    rb_define_method(rb_cMethod, "hash", method_hash, 0);
2633 2640
    rb_define_method(rb_cMethod, "clone", method_clone, 0);
2634 2641
    rb_define_method(rb_cMethod, "call", rb_method_call, -1);
2642
    rb_define_method(rb_cMethod, "curry", rb_method_curry, -1);
2635 2643
    rb_define_method(rb_cMethod, "[]", rb_method_call, -1);
2636 2644
    rb_define_method(rb_cMethod, "arity", method_arity_m, 0);
2637 2645
    rb_define_method(rb_cMethod, "inspect", method_inspect, 0);
test/ruby/test_method.rb
754 754
    m = assert_nothing_raised(NameError, feature8391) {break o.singleton_method(:bar)}
755 755
    assert_equal(:bar, m.call, feature8391)
756 756
  end
757

  
758
  def test_curry
759
    c = Class.new
760
    p = proc {|a,b,c| a + b + c }
761
    c.class_eval { define_method(:three_args, p) }
762
    curried = c.new.method(:three_args).curry
763

  
764
    assert_equal(6, curried.(1).(2).(3))
765
  end
757 766
end
758
-