Skip to content

Commit 4722c20

Browse files
committed
* 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
1 parent 04fd9ac commit 4722c20

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Mon Jan 7 20:48:47 2013 Shugo Maeda <shugo@ruby-lang.org>
2+
3+
* eval.c (Init_eval): main.include should be private.
4+
[ruby-core:51293] [Bug #7670]
5+
6+
* test/ruby/test_module.rb (test_top_include_is_private): a new test
7+
for the above change.
8+
19
Mon Jan 7 20:29:50 2013 Shugo Maeda <shugo@ruby-lang.org>
210

311
* NEWS: remove description about `require "refinement"'.

eval.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,8 @@ Init_eval(void)
15511551
rb_define_singleton_method(rb_cModule, "nesting", rb_mod_nesting, 0);
15521552
rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, -1);
15531553

1554-
rb_define_singleton_method(rb_vm_top_self(), "include", top_include, -1);
1554+
rb_define_private_method(rb_singleton_class(rb_vm_top_self()),
1555+
"include", top_include, -1);
15551556
rb_define_private_method(rb_singleton_class(rb_vm_top_self()),
15561557
"using", top_using, 1);
15571558

test/ruby/test_module.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,4 +1596,23 @@ def test_remove_const
15961596
m = Module.new
15971597
assert_raise(NameError){ m.instance_eval { remove_const(:__FOO__) } }
15981598
end
1599+
1600+
def test_top_include_is_private
1601+
main = eval("self", TOPLEVEL_BINDING)
1602+
methods = main.singleton_class.private_instance_methods(false)
1603+
assert(methods.include?(:include))
1604+
1605+
assert_in_out_err([], <<-INPUT, ["true"], [])
1606+
module M
1607+
end
1608+
include M
1609+
p singleton_class < M
1610+
INPUT
1611+
1612+
assert_in_out_err([], <<-INPUT, [], /private method `include' called for main:Object \(NoMethodError\)/)
1613+
module M
1614+
end
1615+
self.include M
1616+
INPUT
1617+
end
15991618
end

0 commit comments

Comments
 (0)