summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-10-27 15:36:00 -0700
committerJeremy Evans <code@jeremyevans.net>2021-12-09 12:59:37 -0800
commit27278150685e738f84105d09843d3ba371146c7a (patch)
tree2999a2683e67b9c63a9d44faac52e2d67152ee37 /test/ruby
parent74159f7f3e58d8e5ef2e6ee430b7ffa2ade5d952 (diff)
Add {Method,UnboundMethod}#{public?,private?,protected?}
These methods allow for checking whether the method has that visibility. Implements [Feature #11689]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5040
Diffstat (limited to 'test/ruby')
-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 daf0ec73ca..da68787933 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -1181,6 +1181,25 @@ class TestMethod < Test::Unit::TestCase
assert_nil(super_method)
end
+ def test_method_visibility_predicates
+ v = Visibility.new
+ assert_equal(true, v.method(:mv1).public?)
+ assert_equal(true, v.method(:mv2).private?)
+ assert_equal(true, v.method(:mv3).protected?)
+ assert_equal(false, v.method(:mv2).public?)
+ assert_equal(false, v.method(:mv3).private?)
+ assert_equal(false, v.method(:mv1).protected?)
+ end
+
+ def test_unbound_method_visibility_predicates
+ assert_equal(true, Visibility.instance_method(:mv1).public?)
+ assert_equal(true, Visibility.instance_method(:mv2).private?)
+ assert_equal(true, Visibility.instance_method(:mv3).protected?)
+ assert_equal(false, Visibility.instance_method(:mv2).public?)
+ assert_equal(false, Visibility.instance_method(:mv3).private?)
+ assert_equal(false, Visibility.instance_method(:mv1).protected?)
+ end
+
def rest_parameter(*rest)
rest
end