From ad29527920b2a37ee427dc4991ff74d7a2f53e05 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 30 Jun 2023 17:04:52 -0700 Subject: Fix Module#define_method to change visibility when passed existing method body Fixes [Bug #19749] --- test/ruby/test_module.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/ruby') 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 -- cgit v1.2.3