From 25f5dd6799bbacc9f61d60b87b70ea6e6d815c20 Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 13 Nov 2015 17:38:12 +0000 Subject: * vm.c (vm_define_method): do not use current CREF immediately, but check CREF in environment or methods. Methods defined in methods should be public. [Bug #11571] * vm_method.c (rb_scope_module_func_check): check CREF in env or me. if CREF is contained by `me', then return FALSE. * test/ruby/test_method.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_method.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index e8b8b4b86f..9e20d5cc22 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -919,4 +919,21 @@ class TestMethod < Test::Unit::TestCase assert_equal(456, b.local_variable_get(:bar)) assert_equal([:bar, :foo], b.local_variables.sort) end + + class MethodInMethodClass + def m1 + def m2 + end + end + private + end + + def test_method_in_method_visibility_should_be_public + assert_equal([:m1].sort, MethodInMethodClass.public_instance_methods(false).sort) + assert_equal([].sort, MethodInMethodClass.private_instance_methods(false).sort) + + MethodInMethodClass.new.m1 + assert_equal([:m1, :m2].sort, MethodInMethodClass.public_instance_methods(false).sort) + assert_equal([].sort, MethodInMethodClass.private_instance_methods(false).sort) + end end -- cgit v1.2.3