summaryrefslogtreecommitdiff
path: root/test/ruby/test_method.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-31 15:00:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-31 15:00:37 +0000
commit67c574736912003c377218153f9d3b9c0c96a17b (patch)
tree558aea841613b06f6913d1ab22942aecc531a317 /test/ruby/test_method.rb
parent4a6f7633303f2d6eb5ec164dc656cf5d47531960 (diff)
Method reference operator
Introduce the new operator for method reference, `.:`. [Feature #12125] [Feature #13581] [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_method.rb')
-rw-r--r--test/ruby/test_method.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index a9051b81fa..5cfcdb8dc5 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -1095,4 +1095,23 @@ class TestMethod < Test::Unit::TestCase
(f >> 5).call(2)
}
end
+
+ def test_method_reference_operator
+ m = 1.:succ
+ assert_equal(1.method(:succ), m)
+ assert_equal(2, m.())
+ m = 1.:+
+ assert_equal(1.method(:+), m)
+ assert_equal(42, m.(41))
+ m = 1.:-@
+ assert_equal(1.method(:-@), m)
+ assert_equal(-1, m.())
+ o = Object.new
+ def o.foo; 42; end
+ m = o.method(:foo)
+ assert_equal(m, o.:foo)
+ def o.method(m); nil; end
+ assert_equal(m, o.:foo)
+ assert_nil(o.method(:foo))
+ end
end