From: MikkelFJ Date: 2002-08-16T22:56:43+09:00 Subject: Re: Thought question: Where does "new" come from? > For example > > pigeon% cat b.rb > #!/usr/bin/ruby > class A > class << self > @@a = 12 > end > p @@a > end > pigeon% > > with 1.6.7 the class variable is defined in the singleton class > > pigeon% /usr/bin/ruby -v b.rb > ruby 1.6.7 (2002-03-01) [i686-linux] > b.rb:4: warning: declaring singleton class variable > b.rb:6: uninitialized class variable @@a in A (NameError) > pigeon% Actually I get "12" and no error using 1.6.6 on Windows. In the following the ruby interpreter yields a parse error in class B at the line @@a = "hello" in class B. I irb I get "hello" printed. At some point I was required to assign @@a as in class C or I would get a not initialized error, but I no longer remember how because now class C works. Anyway I don't think I'll bother more with that before there is a 1.6.8 release for Windows. puts "--- A ---" class A class << self @@a = 12 end p @@a end puts "--- B --- class B end class << B def hello @@a = "hello" end end B.hello puts "--- C ---" class C @@a = "hello" end def C.hello @@a = "hello" end C.hello