ruby-changes:26681
From: shugo <ko1@a...>
Date: Mon, 7 Jan 2013 21:42:59 +0900 (JST)
Subject: [ruby-changes:26681] shugo:r38732 (trunk): * vm_method.c (Init_eval_method): main.public and main.private
shugo 2013-01-07 21:42:48 +0900 (Mon, 07 Jan 2013) New Revision: 38732 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38732 Log: * vm_method.c (Init_eval_method): main.public and main.private should be private. * proc.c (Init_Proc): main.define_method should be private. * test/ruby/test_module.rb: related test. Modified files: trunk/ChangeLog trunk/proc.c trunk/test/ruby/test_module.rb trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 38731) +++ ChangeLog (revision 38732) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jan 7 21:40:36 2013 Shugo Maeda <shugo@r...> + + * vm_method.c (Init_eval_method): main.public and main.private + should be private. + + * proc.c (Init_Proc): main.define_method should be private. + + * test/ruby/test_module.rb: related test. + Mon Jan 7 20:48:47 2013 Shugo Maeda <shugo@r...> * eval.c (Init_eval): main.include should be private. Index: proc.c =================================================================== --- proc.c (revision 38731) +++ proc.c (revision 38732) @@ -2286,7 +2286,8 @@ Init_Proc(void) https://github.com/ruby/ruby/blob/trunk/proc.c#L2286 /* Kernel */ rb_define_method(rb_mKernel, "define_singleton_method", rb_obj_define_method, -1); - rb_define_singleton_method(rb_vm_top_self(), "define_method", top_define_method, -1); + rb_define_private_method(rb_singleton_class(rb_vm_top_self()), + "define_method", top_define_method, -1); } /* Index: vm_method.c =================================================================== --- vm_method.c (revision 38731) +++ vm_method.c (revision 38732) @@ -1610,8 +1610,10 @@ Init_eval_method(void) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1610 rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1); rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1); - rb_define_singleton_method(rb_vm_top_self(), "public", top_public, -1); - rb_define_singleton_method(rb_vm_top_self(), "private", top_private, -1); + rb_define_private_method(rb_singleton_class(rb_vm_top_self()), + "public", top_public, -1); + rb_define_private_method(rb_singleton_class(rb_vm_top_self()), + "private", top_private, -1); object_id = rb_intern("object_id"); added = rb_intern("method_added"); Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 38731) +++ test/ruby/test_module.rb (revision 38732) @@ -1597,22 +1597,22 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1597 assert_raise(NameError){ m.instance_eval { remove_const(:__FOO__) } } end - def test_top_include_is_private - main = eval("self", TOPLEVEL_BINDING) - methods = main.singleton_class.private_instance_methods(false) - assert(methods.include?(:include)) + def test_private_top_methods + assert_top_method_is_private(:include) + assert_top_method_is_private(:public) + assert_top_method_is_private(:private) + assert_top_method_is_private(:define_method) + end - assert_in_out_err([], <<-INPUT, ["true"], []) - module M - end - include M - p singleton_class < M - INPUT + private + + def assert_top_method_is_private(method) + top = eval("self", TOPLEVEL_BINDING) + methods = top.singleton_class.private_instance_methods(false) + assert(methods.include?(method), "#{method} should be private") - assert_in_out_err([], <<-INPUT, [], /private method `include' called for main:Object \(NoMethodError\)/) - module M - end - self.include M + assert_in_out_err([], <<-INPUT, [], /private method `#{method}' called for main:Object \(NoMethodError\)/) + self.#{method} INPUT end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/