mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4722c20661
commit
19768b6cac
4 changed files with 29 additions and 17 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Mon Jan 7 21:40:36 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Mon Jan 7 20:48:47 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (Init_eval): main.include should be private.
|
* eval.c (Init_eval): main.include should be private.
|
||||||
|
|
3
proc.c
3
proc.c
|
@ -2286,7 +2286,8 @@ Init_Proc(void)
|
||||||
/* Kernel */
|
/* Kernel */
|
||||||
rb_define_method(rb_mKernel, "define_singleton_method", rb_obj_define_method, -1);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1597,22 +1597,22 @@ class TestModule < Test::Unit::TestCase
|
||||||
assert_raise(NameError){ m.instance_eval { remove_const(:__FOO__) } }
|
assert_raise(NameError){ m.instance_eval { remove_const(:__FOO__) } }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_top_include_is_private
|
def test_private_top_methods
|
||||||
main = eval("self", TOPLEVEL_BINDING)
|
assert_top_method_is_private(:include)
|
||||||
methods = main.singleton_class.private_instance_methods(false)
|
assert_top_method_is_private(:public)
|
||||||
assert(methods.include?(:include))
|
assert_top_method_is_private(:private)
|
||||||
|
assert_top_method_is_private(:define_method)
|
||||||
|
end
|
||||||
|
|
||||||
assert_in_out_err([], <<-INPUT, ["true"], [])
|
private
|
||||||
module M
|
|
||||||
end
|
|
||||||
include M
|
|
||||||
p singleton_class < M
|
|
||||||
INPUT
|
|
||||||
|
|
||||||
assert_in_out_err([], <<-INPUT, [], /private method `include' called for main:Object \(NoMethodError\)/)
|
def assert_top_method_is_private(method)
|
||||||
module M
|
top = eval("self", TOPLEVEL_BINDING)
|
||||||
end
|
methods = top.singleton_class.private_instance_methods(false)
|
||||||
self.include M
|
assert(methods.include?(method), "#{method} should be private")
|
||||||
|
|
||||||
|
assert_in_out_err([], <<-INPUT, [], /private method `#{method}' called for main:Object \(NoMethodError\)/)
|
||||||
|
self.#{method}
|
||||||
INPUT
|
INPUT
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1610,8 +1610,10 @@ Init_eval_method(void)
|
||||||
rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1);
|
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_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_private_method(rb_singleton_class(rb_vm_top_self()),
|
||||||
rb_define_singleton_method(rb_vm_top_self(), "private", top_private, -1);
|
"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");
|
object_id = rb_intern("object_id");
|
||||||
added = rb_intern("method_added");
|
added = rb_intern("method_added");
|
||||||
|
|
Loading…
Reference in a new issue