From: Kent Dahl Date: 2002-10-12T01:57:17+09:00 Subject: Re: Different Behavior of Class Variables w.r.t ||= nobu.nokada@softhome.net wrote: > At Sat, 12 Oct 2002 00:57:04 +0900, > Kent Dahl wrote: > > 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] I am not too sure which way it has been made consistent. Does ||= work on all variables similarly now? It looks like it, from what I can gather from the patch source... *cvs update, compile* ... yup, ||= works on all now. If all types of variables now work with ||=, that isn't necessarily a bad idea, but writing Ruby code that sets a class variable using ||= somewhere which might cause it to be defined at the wrong hierarchy level might be a bad idea. As for what Ruby should do, it really is a weighing of "shooting foot" versus "ease of toe nail cutting" that it appears Matz already has made a call on. :-) I will probably succumb to using the terser ||= with class variables myself over time, but I have already learned the pitfall. Don't know about nubies, as YMMV. -- (\[ Kent Dahl ]/)_ _~_ __[ http://www.stud.ntnu.no/~kentda/ ]___/~ ))\_student_/(( \__d L b__/ NTNU - graduate engineering - 5. year ) ( \__\_�|�_/__/ ) _)Industrial economics and technological management( \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___)