From: John Lane Date: 2010-02-10T02:47:06+09:00 Subject: Re: Mixin module with class variables and class methods Marnen Laibow-Koser wrote: >> 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. snip > In other words, class @instance variables act just like @@class > variables but without the problems. > Ok so I get that point. I've now got working code, well almost. I mix the module into multiple classes and each gets their own instance of the variable, which is not what I need. Here's the code: http://pastie.org/816654 There are three classes, One, Two and Three. Classes One and Two both mix in the module. Class Three is a subclass of class Two and therefore does not directly mix in the module. The output i get demonstrates that each class gets its own instance of the variable that I want to be shared across all three. Here is the output: TestMixin included in One b added for class One : a b c added for class One : a b c TestMixin included in Two d added for class Two : a d e added for class Two : a d e f added for class Three : f g added for class Three : f g the list for class One is a b c the list for class Two is a d e the list for class Three is f g What I want to get is this: TestMixin included in One b added for class One : a b c added for class One : a b c TestMixin included in Two d added for class Two : a b c d e added for class Two : a b c d e f added for class Three : a b c d e f g added for class Three : a b c d e f g the list for class One is a b c d e f g the list for class Two is a b e d e f g the list for class Three is a b c d e f g -- Posted via http://www.ruby-forum.com/.