From: Florian Gross Date: 2005-03-31T04:54:44+09:00 Subject: Re: Defining a Class Accessor Navindra Umanee wrote: > Florian Gross wrote: > >>Do you really need to use @@variables? From my experience they tend to >>cause trouble. > > Could you explain why they would cause trouble? I thought the original post would answer that well enough already, but in my own Ruby experience I have so far being surprised when using them. Why should they be used when you can use far simpler constructs with clearer rules? Generally they seem to be used most as a quick replacement for instance variables when something goes wrong without further questioning or actually finding the root of the problem. I've seen them used quite frequently in this case: module StackMixIn def push(item) @items << item end def pop() @items.pop end # I'd like to initialize @items, but this will not work: @items = [] # If I just replace every '@items' with '@@items' it will magically # work. It's an obvious fix. It must be in Ruby exactly as a fix for # this kind of situation. end (And yes, I know that they are going to be simplified in Rite, but I'm not sure if that is going to make them completely non-surprising to most people...)