ruby-changes:28294
From: nobu <ko1@a...>
Date: Thu, 18 Apr 2013 16:59:18 +0900 (JST)
Subject: [ruby-changes:28294] nobu:r40346 (trunk): vm_method.c: fix visibility on anonymous module
nobu 2013-04-18 16:59:06 +0900 (Thu, 18 Apr 2013) New Revision: 40346 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40346 Log: vm_method.c: fix visibility on anonymous module * vm_method.c (rb_mod_public_method): fix visibility on anonymous module. set visibility of singleton method, not method in base class. [ruby-core:54404] [Bug #8284] Modified files: trunk/ChangeLog trunk/test/ruby/test_module.rb trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 40345) +++ ChangeLog (revision 40346) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Apr 18 16:58:51 2013 Nobuyoshi Nakada <nobu@r...> + + * vm_method.c (rb_mod_public_method): fix visibility on anonymous + module. set visibility of singleton method, not method in base + class. [ruby-core:54404] [Bug #8284] + Thu Apr 18 16:20:51 2013 Nobuyoshi Nakada <nobu@r...> * dir.c (glob_helper): should skip dot directories only for recursion, Index: vm_method.c =================================================================== --- vm_method.c (revision 40345) +++ vm_method.c (revision 40346) @@ -1374,7 +1374,7 @@ rb_mod_private(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1374 static VALUE rb_mod_public_method(int argc, VALUE *argv, VALUE obj) { - set_method_visibility(CLASS_OF(obj), argc, argv, NOEX_PUBLIC); + set_method_visibility(rb_singleton_class(obj), argc, argv, NOEX_PUBLIC); return obj; } @@ -1400,7 +1400,7 @@ rb_mod_public_method(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1400 static VALUE rb_mod_private_method(int argc, VALUE *argv, VALUE obj) { - set_method_visibility(CLASS_OF(obj), argc, argv, NOEX_PRIVATE); + set_method_visibility(rb_singleton_class(obj), argc, argv, NOEX_PRIVATE); return obj; } Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 40345) +++ test/ruby/test_module.rb (revision 40346) @@ -1721,6 +1721,13 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1721 assert_equal [mod, obj.singleton_class, Object], obj.singleton_class.ancestors.first(3) end + def test_anonymous_module_public_class_method + bug8284 = '[ruby-core:54404] [Bug #8284]' + assert_raise(NoMethodError) {Object.define_method} + Module.new.public_class_method(:define_method) + assert_raise(NoMethodError, bug8284) {Object.define_method} + end + private def assert_top_method_is_private(method) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/