From: Shugo Maeda Date: 2011-07-16T20:50:29+09:00 Subject: [ruby-dev:44119] [Ruby 1.9 - Bug #4971] Module#class_variables Issue #4971 has been updated by Shugo Maeda. File class_variables.diff added 前田です。 Shugo Maeda wrote: > 個人的には、Module#class_variablesもModule#constantsのように引数でコントロールできる > ようにする(デフォルトではスーパークラスも探索する)のがよいと思います。 この方針で作ったパッチを添付しておきます。 # trunkならRails風に勝手にcommitしてもいいんですかね。 ---------------------------------------- Bug #4971: Module#class_variables http://redmine.ruby-lang.org/issues/4971 Author: Shugo Maeda Status: Open Priority: Normal Assignee: Yukihiro Matsumoto Category: core Target version: 1.9.x ruby -v: - Ruby 1.9だとModule#class_variablesはスーパークラスのクラス変数を返しませんが、仕様でしょうか? class Foo @@foo = 123 end class Bar < Foo @@bar = 456 end p Bar.class_variables #=> 1.8では["@@bar", "@@foo"], 1.9では[:@@bar] commit logには * variable.c (rb_mod_class_variables): class variables are no longer inherited. [ruby-dev:23808] と書いてあるのですが、当時のクラス変数の仕様って今の1.8とも1.9とも違う 仕様だったりするでしょうか。 Bar.class_variable_get(:@@foo)で値は取れるので、class_variablesで:@@fooを 返してもよい気がするのですが。 -- http://redmine.ruby-lang.org