From: Robert Dober Date: 2007-05-02T07:11:19+09:00 Subject: Re: simple subclass question On 5/1/07, Ball, Donald A Jr (Library) wrote: > Thanks to you and Robert for the quick answers. I think I get it now; I > was a little fuzzy on the notion of class instance variables before. I > now use a construct like so: > > class A > class << self > attr_accessor :var > end > end > > class B < A > class << self > def var > @var || superclass.var > end > end > end > > to allow subclasses's instance variables to default to their > superclass's until and unless overridden. That was the point I missed, but of course you did that nicely :). I'll admit the class << self > syntax continues to mystify somewhat; can anyone proffer an explanation > that would help me grok it fully? I will take a chance by saying that class << A def x... end end is the same as class A def self.x end end although there might be some subtle differences Do e.g, this class << A puts self end you can see kind of a Proxy object, but it behaves pretty much transparently. Cheers Robert -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw