Hi,

Am Sonntag, 07. Okt 2007, 22:56:54 +0900 schrieb David A. Black:
> On Sun, 7 Oct 2007, Bertram Scharpf wrote:
>> Am Sonntag, 07. Okt 2007, 21:39:24 +0900 schrieb David A. Black:
>>> If you want to represent state per class, the best way is to give your
>>> class an instance variable or accessor:
>>>
>>>   class C
>>>     class << self    # C's singleton class
>>>       attr_accessor :var
>>>     end
>>>   end
>>
>> I do this all the time. But:
>>
>>  class D < C ; end
>>
>> Always keep in mind that `D.var' will be something different
>> than `C.var'.
>
> That's the point of attr_accessor: to give easy access to per-object
> state.

About a month ago I found myself doing even this:

  class C
    @x = "x-default"
    class <<self
      def x ; @x or superclass.x ; end
    end
  end

  class D < C ; end
  class E < D ; @x = "x-special" ; end

  puts C.x
  puts D.x
  puts E.x

I still don't know what is better: using stable instance
methods (same value on every call) or doing it this way.

Bertram


-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de