John Lane wrote: > Brian Candler wrote: >> Class variables are a pain, for exactly this sort of reason. > > Yes, I'm getting that feeling! My example test was just a simplified > model to understand how it worked and, in the case of the example, I can > see instance variables provide a solution. > > What I'm trying to do is end up with a module mixed into a number of > classes that will each call a mixed-in class method to add values to a > class variable that will be a hash. Other instance methods in the mixin > will then make use of the information in the class variable hash. > > So I think I really need a class variable. But you're probably wrong. What you probably want is a class instance variable -- a weird concept, to be sure, until you recall that in Ruby classes are instances of class Class. So: class MyClass @@class_var = 'foo' @class_ivar = 'bar' def self.class_method puts @@class_var puts @class_ivar end end puts MyClass.class_method # prints 'foo' and 'bar' In other words, class @instance variables act just like @@class variables but without the problems. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen / marnen.org -- Posted via http://www.ruby-forum.com/.