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

ruby-changes:18691

From: mame <ko1@a...>
Date: Sat, 29 Jan 2011 03:02:15 +0900 (JST)
Subject: [ruby-changes:18691] Ruby:r30716 (trunk): * variable.c (rb_mod_const_of, sv_i): Module#constant should exclude

mame	2011-01-29 02:57:48 +0900 (Sat, 29 Jan 2011)

  New Revision: 30716

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

  Log:
    * variable.c (rb_mod_const_of, sv_i): Module#constant should exclude
      private constants.  see [ruby-core:32912].
    
    * test/ruby/test_module.rb (test_constants_with_private_constant): add
      a test for above.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30715)
+++ ChangeLog	(revision 30716)
@@ -1,3 +1,11 @@
+Sat Jan 29 02:02:37 2011  Yusuke Endoh  <mame@t...>
+
+	* variable.c (rb_mod_const_of, sv_i): Module#constant should exclude
+	  private constants.  see [ruby-core:32912].
+
+	* test/ruby/test_module.rb (test_constants_with_private_constant): add
+	  a test for above.
+
 Sat Jan 29 01:36:41 2011  Yusuke Endoh  <mame@t...>
 
 	* variable.c (rb_const_set): const_set shoud preserve constant
Index: variable.c
===================================================================
--- variable.c	(revision 30715)
+++ variable.c	(revision 30716)
@@ -1709,7 +1709,7 @@
 {
     if (rb_is_const_id(key)) {
 	if (!st_lookup(tbl, (st_data_t)key, 0)) {
-	    st_insert(tbl, (st_data_t)key, (st_data_t)key);
+	    st_insert(tbl, (st_data_t)key, (st_data_t)ce);
 	}
     }
     return ST_CONTINUE;
@@ -1742,9 +1742,11 @@
 }
 
 static int
-list_i(ID key, ID value, VALUE ary)
+list_i(st_data_t key, st_data_t value, VALUE ary)
 {
-    rb_ary_push(ary, ID2SYM(key));
+    ID sym = (ID)key;
+    rb_const_entry_t *ce = (rb_const_entry_t *)value;
+    if (ce->flag != CONST_PRIVATE) rb_ary_push(ary, ID2SYM(sym));
     return ST_CONTINUE;
 }
 
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 30715)
+++ test/ruby/test_module.rb	(revision 30716)
@@ -981,4 +981,8 @@
     c.public_constant(:FOO)
     assert_equal("foo", c::FOO)
   end
+
+  def test_constants_with_private_constant
+    assert(!(::TestModule).constants.include?(:PrivateClass))
+  end
 end

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

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