From 3b7b70650c744f8d045328f782fcad360bdd9f46 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 22 Nov 2018 05:51:42 +0000 Subject: 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_proc.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'test/ruby/test_proc.rb') diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 7ea4556e8a..f70345ed74 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -1460,11 +1460,22 @@ class TestProc < Test::Unit::TestCase 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 -- cgit v1.2.3