Gavin Kistner wrote:
> On Nov 21, 2004, at 3:05 PM, Gavin Kistner wrote:
> 
>> Summary:
>> How would you store information about a class, which exposes that 
>> information in an inherited manner that matches the inheritance 
>> hierarchy of the class?
> 
> 
> I forgot to add: I also need it to be able to support the 'inheritance 
> hierarchy' that comes when using mixing to extend a class.

You could do it with constants. So, instead of your original example:


     class LightSwitch
         def turn_on
             #...
         end
         def turn_off
             #...
         end
         describe_method :turn_on, "Turn the switch on"
         describe_method :turn_off, "Turn the switch off"
     end

     class Dimmer < LightSwitch
         def set_level( n )
             #...
         end
         describe_method :set_level, "Set the brightness level"
     end

You might use a naming scheme like the following (to avoid conflicts):

     class LightSwitch
         def turn_on
             #...
         end
         def turn_off
             #...
         end
         DESCRIBE_METHOD_turn_on  = "Turn the switch on"
         DESCRIBE_METHOD_turn_off = "Turn the switch off"
     end

     class Dimmer < LightSwitch
         def set_level( n )
             #...
         end
         DESCRIBE_METHOD_set_level = "Set the brightness level"
     end


That approach handles inheritance, and works fine with modules, but you 
have to use const_get (or eval) to look up method descriptions given a 
method name. You could even make the interface look like 
describe_method() using const_set. Another option is to use a data 
structure that provides some kind of inheritance. I wrote superhash (see 
RAA) to do just that. There is some sugar called "class_superhash" that 
is almost what you want, but it doesn't deal with module inclusion. 
Could be adapted to do so, though.