From: Koji Arai Date: 2001-04-22T02:23:54+09:00 Subject: [ruby-dev:13019] const_defined?(:@@cvar) 新井です。 const_defined? がクラス変数に対して真を返すのは仕様ですか? # const_get/const_set も 実装が見えかくれしますがメタな機能だから仕様でもいいのかもし れない。。。仕様だとして、const_set/const_get がクラス変数を 想定してない挙動を示す場合があります。 module Foo @@foo = 1 p const_defined? :@@foo # => true p const_get(:@@foo) # => 1 p const_set(:@@foo, 1) # => -:6: warning: already initialized constant @@foo # => 1 const_set(:@@bar, 2) p @@bar # => 2 p defined? @@bar # => "class variable" p const_get(:@@baz) # => -:12:in `const_get': uninitialized constant @@baz (NameError) end const_set で、大文字で始まらない定数を定義できる(const_get で参照できる) とドキュメントには書いたのですが、これも仕様? (一応確認)。 module Foo const_set(:foo, 1) p const_get(:foo) end -- 新井康司 (Koji Arai)