1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2011-01-28 17:57:48 +00:00
parent b1e829fb30
commit b511e1bfbe
3 changed files with 17 additions and 3 deletions

View file

@ -1,3 +1,11 @@
Sat Jan 29 02:02:37 2011 Yusuke Endoh <mame@tsg.ne.jp>
* 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@tsg.ne.jp> Sat Jan 29 01:36:41 2011 Yusuke Endoh <mame@tsg.ne.jp>
* variable.c (rb_const_set): const_set shoud preserve constant * variable.c (rb_const_set): const_set shoud preserve constant

View file

@ -981,4 +981,8 @@ class TestModule < Test::Unit::TestCase
c.public_constant(:FOO) c.public_constant(:FOO)
assert_equal("foo", c::FOO) assert_equal("foo", c::FOO)
end end
def test_constants_with_private_constant
assert(!(::TestModule).constants.include?(:PrivateClass))
end
end end

View file

@ -1709,7 +1709,7 @@ sv_i(ID key, rb_const_entry_t *ce, st_table *tbl)
{ {
if (rb_is_const_id(key)) { if (rb_is_const_id(key)) {
if (!st_lookup(tbl, (st_data_t)key, 0)) { 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; return ST_CONTINUE;
@ -1742,9 +1742,11 @@ rb_mod_const_of(VALUE mod, void *data)
} }
static int 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; return ST_CONTINUE;
} }