From: "David A. Black" Date: 2007-10-18T05:13:58+09:00 Subject: Re: Class instance variable idiom Hi -- On Thu, 18 Oct 2007, Perry Smith wrote: > I am using this technique for class instance variables: > > class << self > def set_foo(s) > @foo = s > end > alias :foo= :set_foo > > def foo > @foo > end > end > > Then to reference foo from an instance of the class (or subclass), I do: > > self.class.foo > > Is there a cleaner way, in particular for the reference of the class > instance variable, to do this? Yes: class C class << self attr_accessor :foo end end David -- Upcoming training from Ruby Power and Light, LLC: * Intro to Ruby on Rails, Edison, NJ, October 23-26 * Advancing with Rails, Edison, NJ, November 6-9 Both taught by David A. Black. See http://www.rubypal.com for more info!