mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* eval.c (Init_eval): main.include should be private.
[ruby-core:51293] [Bug #7670] * test/ruby/test_module.rb (test_top_include_is_private): a new test for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
04fd9aceab
commit
4722c20661
3 changed files with 29 additions and 1 deletions
|
@ -1,3 +1,11 @@
|
|||
Mon Jan 7 20:48:47 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* eval.c (Init_eval): main.include should be private.
|
||||
[ruby-core:51293] [Bug #7670]
|
||||
|
||||
* test/ruby/test_module.rb (test_top_include_is_private): a new test
|
||||
for the above change.
|
||||
|
||||
Mon Jan 7 20:29:50 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* NEWS: remove description about `require "refinement"'.
|
||||
|
|
3
eval.c
3
eval.c
|
@ -1551,7 +1551,8 @@ Init_eval(void)
|
|||
rb_define_singleton_method(rb_cModule, "nesting", rb_mod_nesting, 0);
|
||||
rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, -1);
|
||||
|
||||
rb_define_singleton_method(rb_vm_top_self(), "include", top_include, -1);
|
||||
rb_define_private_method(rb_singleton_class(rb_vm_top_self()),
|
||||
"include", top_include, -1);
|
||||
rb_define_private_method(rb_singleton_class(rb_vm_top_self()),
|
||||
"using", top_using, 1);
|
||||
|
||||
|
|
|
@ -1596,4 +1596,23 @@ class TestModule < Test::Unit::TestCase
|
|||
m = Module.new
|
||||
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))
|
||||
|
||||
assert_in_out_err([], <<-INPUT, ["true"], [])
|
||||
module M
|
||||
end
|
||||
include M
|
||||
p singleton_class < M
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, [], /private method `include' called for main:Object \(NoMethodError\)/)
|
||||
module M
|
||||
end
|
||||
self.include M
|
||||
INPUT
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue