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 /test/ruby/test_proc.rb | |
parent | 4eaf22cc3f6639003ed3b64c3fee82c5867d27ea (diff) |
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 <[email protected]>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_proc.rb')
-rw-r--r-- | test/ruby/test_proc.rb | 17 |
1 files changed, 14 insertions, 3 deletions
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 |