[前][次][番号順一覧][スレッド一覧]

ruby-changes:26680

From: shugo <ko1@a...>
Date: Mon, 7 Jan 2013 20:56:54 +0900 (JST)
Subject: [ruby-changes:26680] shugo:r38731 (trunk): * eval.c (Init_eval): main.include should be private.

shugo	2013-01-07 20:55:17 +0900 (Mon, 07 Jan 2013)

  New Revision: 38731

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38731

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/eval.c
    trunk/test/ruby/test_module.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38730)
+++ ChangeLog	(revision 38731)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jan  7 20:48:47 2013  Shugo Maeda  <shugo@r...>
+
+	* 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@r...>
 
 	* NEWS: remove description about `require "refinement"'.
Index: eval.c
===================================================================
--- eval.c	(revision 38730)
+++ eval.c	(revision 38731)
@@ -1551,7 +1551,8 @@ Init_eval(void) https://github.com/ruby/ruby/blob/trunk/eval.c#L1551
     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);
 
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 38730)
+++ test/ruby/test_module.rb	(revision 38731)
@@ -1596,4 +1596,23 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1596
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]