summaryrefslogtreecommitdiff
path: root/test/ruby/test_method.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-22 05:51:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-22 05:51:41 +0000
commit4eaf22cc3f6639003ed3b64c3fee82c5867d27ea (patch)
tree5d25fc2d01521c27cc5f3df1255a4036b0677e31 /test/ruby/test_method.rb
parenta43e967b8d277fee5cf18329b26bc5c31a3e0363 (diff)
proc.c: Implement Method#* for Method composition
* proc.c (rb_method_compose): Implement Method#* for Method composition, which delegates to Proc#*. * test/ruby/test_method.rb: Add test cases for Method composition. From: Paul Mucur <mudge@mudge.name> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_method.rb')
-rw-r--r--test/ruby/test_method.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index fe0171dd57..80a2669633 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -1040,4 +1040,38 @@ class TestMethod < Test::Unit::TestCase
assert_operator(0.method(:<), :===, 5)
assert_not_operator(0.method(:<), :===, -5)
end
+
+ def test_compose_with_method
+ c = Class.new {
+ def f(x) x * 2 end
+ def g(x) x + 1 end
+ }
+ f = c.new.method(:f)
+ g = c.new.method(:g)
+ h = f * g
+
+ assert_equal(6, h.call(2))
+ end
+
+ def test_compose_with_proc
+ c = Class.new {
+ def f(x) x * 2 end
+ }
+ f = c.new.method(:f)
+ g = proc {|x| x + 1}
+ h = f * g
+
+ assert_equal(6, h.call(2))
+ end
+
+ def test_compose_with_nonproc_or_method
+ c = Class.new {
+ def f(x) x * 2 end
+ }
+ f = c.new.method(:f)
+
+ assert_raise(TypeError) {
+ f * 5
+ }
+ end
end