From: nobu.nokada@... Date: 2002-10-12T01:26:44+09:00 Subject: Re: Different Behavior of Class Variables w.r.t ||= Hi, At Sat, 12 Oct 2002 00:57:04 +0900, Kent Dahl wrote: > > > Yes, if the class var is already initialized. However (1.6.7): > > > > > candle:~$ ruby -ve 'a ||= 3; @a ||= 3; @@a ||= 3' > > > ruby 1.6.7 (2002-03-01) [i686-linux] > > > > This is very interesting. Should Ruby be more consistent in this respect? > > That might be a bad idea, since class variables are more "magical" than > both instance variables and local variables. > > The inheritance hierarchy level where the class variable is first > defined decides where it is visible. This is not a problem with local > variables nor instance variables. Although it is alot more verbose, > using the "@@a = 1 unless defined? @@a" trick gives you the same > functionality, but is easier to spot while reading, if it causes a bug. Oops, 1.7 behavior has changed. Bad idea? # [ruby-talk:50421] & [ruby-dev:18278] -- Nobu Nakada