diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-22 05:51:42 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-22 05:51:42 +0000 |
commit | 3b7b70650c744f8d045328f782fcad360bdd9f46 (patch) | |
tree | 82626e1d7fbe5a1dd3515f612b307024e2bb53f6 /proc.c | |
parent | 4eaf22cc3f6639003ed3b64c3fee82c5867d27ea (diff) | |
download | ruby-3b7b70650c744f8d045328f782fcad360bdd9f46.tar.gz |
proc.c: Support any callable when composing Procs
* proc.c (proc_compose): support any object with a call method rather
than supporting only procs. [Feature #6284]
* proc.c (compose): use the function call on the given object rather
than rb_proc_call_with_block in order to support any object.
* test/ruby/test_proc.rb: Add test cases for composing Procs with
callable objects.
* test/ruby/test_method.rb: Add test cases for composing Methods with
callable objects.
From: Paul Mucur <paul@altmetric.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 16 |
1 files changed, 3 insertions, 13 deletions
@@ -3052,7 +3052,7 @@ compose(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc) 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); } @@ -3061,7 +3061,7 @@ compose(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc) * 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. * @@ -3077,16 +3077,6 @@ proc_compose(VALUE self, VALUE g) 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); @@ -3103,7 +3093,7 @@ proc_compose(VALUE self, VALUE g) * 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. * |