From: Brian Candler Date: 2003-08-06T16:10:56+09:00 Subject: Re: Class variables, module inclusion and instance_eval On Wed, Aug 06, 2003 at 02:55:31PM +0900, Tim Bates wrote: > Somehow, even though the class variable is defined within the context of > the class (via instance_eval) it still gets shared, contrary to the > example of Exhibit B. This is frustrating me, because I want my library > to be able to define a class variable that belongs to only one class, > and I can't find a way to do it. I can't answer your clearly-phrased questions on class variables, but there might be another solution: class instance variables. They are private to the class, not even inherited by subclasses. They're not particularly convenient to use though, because within an instance method, '@foo' refers to the instance variable of the instance of A, not of the class of A. But they do work: module Foo def self.append_features(aModule) super aModule.instance_eval { @foo = Time.now } end def foo self.class.instance_eval { @foo } end end class A include Foo end p A.new.foo sleep 2 class B include Foo end p B.new.foo p A.new.foo Regards, Brian.