eval.c: singleton class constants

* eval.c (rb_mod_s_constants): return its own constants for other
  than Module itself.  [ruby-core:59763] [Bug #9413]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-01-17 08:58:05 +00:00
Родитель 2c3522c3e4
Коммит 5c92de87b4
3 изменённых файлов: 20 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Fri Jan 17 17:58:04 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_mod_s_constants): return its own constants for other
than Module itself. [ruby-core:59763] [Bug #9413]
Tue Jan 16 00:17:00 2014 Kenta Murata <mrkn@mrkn.jp> Tue Jan 16 00:17:00 2014 Kenta Murata <mrkn@mrkn.jp>
* ext/bigdecimal/bigdecimal.gemspec: bigdecimal version 1.2.5. * ext/bigdecimal/bigdecimal.gemspec: bigdecimal version 1.2.5.

4
eval.c
Просмотреть файл

@ -378,8 +378,8 @@ rb_mod_s_constants(int argc, VALUE *argv, VALUE mod)
VALUE cbase = 0; VALUE cbase = 0;
void *data = 0; void *data = 0;
if (argc > 0) { if (argc > 0 || mod != rb_cModule) {
return rb_mod_constants(argc, argv, rb_cModule); return rb_mod_constants(argc, argv, mod);
} }
while (cref) { while (cref) {

Просмотреть файл

@ -866,6 +866,19 @@ class TestModule < Test::Unit::TestCase
m.instance_eval { remove_const(:Foo) } m.instance_eval { remove_const(:Foo) }
end end
class Bug9413
class << self
Foo = :foo
end
end
def test_singleton_constants
bug9413 = '[ruby-core:59763] [Bug #9413]'
c = Bug9413.singleton_class
assert_include(c.constants(true), :Foo, bug9413)
assert_include(c.constants(false), :Foo, bug9413)
end
def test_frozen_class def test_frozen_class
m = Module.new m = Module.new
m.freeze m.freeze