From e2277a5eaf663b0d1eb7d4985ffca1fdb00be0d1 Mon Sep 17 00:00:00 2001 From: shugo Date: Mon, 16 Nov 2009 07:01:44 +0000 Subject: * vm_insnhelper.c (vm_call_method): protected singleton methods of an object should not be able to called from other instances of the class of the object. [ruby-core:26761] * vm_eval.c (rb_method_call_status): ditto. * test/ruby/test_module.rb (test_protected_singleton_method): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_module.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 59c965325..92b2f7b56 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -854,4 +854,28 @@ class TestModule < Test::Unit::TestCase end assert_equal("", stderr) end + + def test_protected_singleton_method + klass = Class.new + x = klass.new + class << x + protected + + def foo + end + end + assert_raise(NoMethodError) do + x.foo + end + klass.send(:define_method, :bar) do + x.foo + end + assert_nothing_raised do + x.bar + end + y = klass.new + assert_raise(NoMethodError) do + y.bar + end + end end -- cgit