summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2023-06-30 17:04:52 -0700
committerJeremy Evans <code@jeremyevans.net>2024-06-06 15:02:04 -0700
commitad29527920b2a37ee427dc4991ff74d7a2f53e05 (patch)
tree57dc116c8d2ac6cc08d76638447ee0282663c250 /test/ruby
parentf789b816520a26244b0441ec4358e61955ef2ef0 (diff)
Fix Module#define_method to change visibility when passed existing method body
Fixes [Bug #19749]
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_module.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 75d8d909d7..370b7351c2 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -3163,6 +3163,19 @@ class TestModule < Test::Unit::TestCase
end;
end
+ def test_define_method_changes_visibility_with_existing_method_bug_19749
+ c = Class.new do
+ def a; end
+ private def b; end
+
+ define_method(:b, instance_method(:b))
+ private
+ define_method(:a, instance_method(:a))
+ end
+ assert_equal([:b], c.public_instance_methods(false))
+ assert_equal([:a], c.private_instance_methods(false))
+ end
+
def test_define_method_with_unbound_method
# Passing an UnboundMethod to define_method succeeds if it is from an ancestor
assert_nothing_raised do