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_method.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 <paul@altmetric.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_method.rb')
-rw-r--r-- | test/ruby/test_method.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 80a2669633..5193ac6889 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -1064,14 +1064,28 @@ class TestMethod < Test::Unit::TestCase 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 |