I think it only gets tricky like you've pointed out if you're trying to do 
default variable initialization values, but on the other hand this is 
probably 99% of the useful purposes of a class_attr is with a default value 
set.  So your point is well taken.

-Jeff

----- Original Message ----- 
From: "Ara.T.Howard" <Ara.T.Howard / noaa.gov>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Monday, July 11, 2005 4:06 PM
Subject: Re: class_attr_accessor


> On Tue, 12 Jul 2005, Jeffrey Moss wrote:
>
>> I was playing around with class variables and class instance variables 
>> because I wanted to implement a certain functionality, while not really 
>> understanding the coexistence of the two, I found the reason the two 
>> exist is quite clear, the class instance variables facilitate "subclass 
>> slots" (as I know them from other languages) while the @@ syntax 
>> facilitates "class slots"
>>
>> I did a google search for "class_attr_accessor" and found that a number 
>> of people have implemented this functionality in their own code.  I 
>> suggest it be officially added to the ruby distribution.
>>
>> Here is an example:
>>
>> class Module
>> private
>> def class_attr_accessor(*attrs)
>>   attrs.each {|attr|
>>     module_eval(<<-EOS)
>>       class << self
>>         def #{attr}; @#{attr}; end
>>         def #{attr}=(v); @#{attr} = v; end
>>       end
>>     EOS
>>   }
>> end
>> end
>>
>> I really don't think a new notation, similar to @@, is necessary, I think 
>> calling obj.class.accessor_name is very nice. In fact having both a 
>> subclass_attr_accessor and a class_attr_accessor wouldn't hurt either. In 
>> that case, class_attr_accessor would just be a way to make @@vars public.
>>
>> -Jeff Moss
>
> check out
>
>   http://raa.ruby-lang.org/project/traits/
>
> inheritence is quite tricky with the impl of class_attr_accessor above.
>
> cheers.
>
> -a
> -- 
> ===============================================================================
> | email :: ara [dot] t [dot] howard [at] noaa [dot] gov
> | phone :: 303.497.6469
> | My religion is very simple.  My religion is kindness.
> | --Tenzin Gyatso
> ===============================================================================
>
>