Feature #6284 » 0003-proc.c-Support-any-callable-when-composing-Procs.patch
proc.c | ||
---|---|---|
VALUE f, g, fargs;
|
||
f = RARRAY_AREF(args, 0);
|
||
g = RARRAY_AREF(args, 1);
|
||
fargs = rb_ary_new3(1, rb_proc_call_with_block(g, argc, argv, passed_proc));
|
||
fargs = rb_ary_new3(1, rb_funcall_with_block(g, idCall, argc, argv, passed_proc));
|
||
return rb_proc_call(f, fargs);
|
||
}
|
||
... | ... | |
* call-seq:
|
||
* prc * g -> a_proc
|
||
*
|
||
* Returns a proc that is the composition of this proc and the given proc <i>g</i>.
|
||
* Returns a proc that is the composition of this proc and the given <i>g</i>.
|
||
* The returned proc takes a variable number of arguments, calls <i>g</i> with them
|
||
* then calls this proc with the result.
|
||
*
|
||
... | ... | |
rb_proc_t *procp;
|
||
int is_lambda;
|
||
if (!rb_obj_is_method(g) && !rb_obj_is_proc(g)) {
|
||
rb_raise(rb_eTypeError,
|
||
"wrong argument type %s (expected Proc/Method)",
|
||
rb_obj_classname(g));
|
||
}
|
||
if (rb_obj_is_method(g)) {
|
||
g = method_to_proc(g);
|
||
}
|
||
args = rb_ary_new3(2, self, g);
|
||
GetProcPtr(self, procp);
|
||
... | ... | |
* call-seq:
|
||
* meth * g -> a_proc
|
||
*
|
||
* Returns a proc that is the composition of this method and the given proc <i>g</i>.
|
||
* Returns a proc that is the composition of this method and the given <i>g</i>.
|
||
* The returned proc takes a variable number of arguments, calls <i>g</i> with them
|
||
* then calls this method with the result.
|
||
*
|
test/ruby/test_method.rb | ||
---|---|---|
assert_equal(6, h.call(2))
|
||
end
|
||
def test_compose_with_nonproc_or_method
|
||
def test_compose_with_callable
|
||
c = Class.new {
|
||
def f(x) x * 2 end
|
||
}
|
||
c2 = Class.new {
|
||
def call(x) x + 1 end
|
||
}
|
||
f = c.new.method(:f)
|
||
g = f * c2.new
|
||
assert_equal(6, g.call(2))
|
||
end
|
||
def test_compose_with_noncallable
|
||
c = Class.new {
|
||
def f(x) x * 2 end
|
||
}
|
||
f = c.new.method(:f)
|
||
g = f * 5
|
||
assert_raise(TypeError) {
|
||
f * 5
|
||
assert_raise(NoMethodError) {
|
||
g.call(2)
|
||
}
|
||
end
|
||
end
|
test/ruby/test_proc.rb | ||
---|---|---|
assert_equal(6, h.call(2))
|
||
end
|
||
def test_compose_with_nonproc_or_method
|
||
def test_compose_with_callable
|
||
f = proc{|x| x * 2}
|
||
c = Class.new {
|
||
def call(x) x + 1 end
|
||
}
|
||
g = f * c.new
|
||
assert_equal(6, g.call(2))
|
||
end
|
||
def test_compose_with_noncallable
|
||
f = proc{|x| x * 2}
|
||
g = f * 5
|
||
assert_raise(TypeError) {
|
||
f * 5
|
||
assert_raise(NoMethodError) {
|
||
g.call(2)
|
||
}
|
||
end
|
||
end
|
- « Previous
- 1
- 2
- 3
- Next »