From 7fbd2f7cc247ee66e877ab3c88f0274834c6b6c7 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Tue, 2 Jul 2019 15:06:54 +0100 Subject: Allow calling a private method with `self.` This makes it consistent with calling private attribute assignment methods, which currently is allowed (e.g. `self.value =`). Calling a private method in this way can be useful when trying to assign the return value to a local variable with the same name. [Feature #11297] [Feature #16123] --- test/ruby/test_method.rb | 2 +- test/ruby/test_module.rb | 3 ++- test/ruby/test_refinement.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 1289b44c63..a8064c47c2 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -673,7 +673,7 @@ class TestMethod < Test::Unit::TestCase assert_nothing_raised { mv3 } assert_nothing_raised { self.mv1 } - assert_raise(NoMethodError) { self.mv2 } + assert_nothing_raised { self.mv2 } assert_nothing_raised { self.mv3 } v = Visibility.new diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 7bb2261ffb..8689c60dcd 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -2479,7 +2479,8 @@ class TestModule < Test::Unit::TestCase assert_include(methods, :#{method}, ":#{method} should be private") assert_raise_with_message(NoMethodError, "private method `#{method}' called for main:Object") { - self.#{method} + recv = self + recv.#{method} } } end diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 87d60e41a4..4be0720983 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -538,7 +538,7 @@ class TestRefinement < Test::Unit::TestCase def test_main_using_is_private assert_raise(NoMethodError) do - eval("self.using Module.new", Sandbox::BINDING) + eval("recv = self; recv.using Module.new", Sandbox::BINDING) end end -- cgit v1.2.3