On Fri, Aug 31, 2001 at 11:22:54PM +0900, David Alan Black wrote:
> 
> Hello --
> 
> On Fri, 31 Aug 2001, Renald Buter wrote:
> 
> >
> > Hello,
> >
> > Does anyone have an idea how to dynamically add a _class_ variable to
> > extending classes?
> >
> > I have code like this:
> >
> > <code>
> >
> >   class A
> ...
> >             def properties
> >               ### >> ACCESS CLASS VARIABLE << ###
> >             end
> ...
> 
> At the cost of sounding thick, I'll say that I'm not sure exactly what
> you're trying to do.  Can you explain a little more, or provide a
> smaller example?  (Or wait for someone who gets it to answer you :-)

At the moment I wrote the example, I already suspected this :)


In plain text, this is what I am looking for. I add the 'property'
METHOD to the inheriting classes of A. This creates the methods for the
properties, a.k.a. 'attr_xx' family.

e.g. 
	class B < A
		property :max, 0
		property :min, -10
	end

would create methods 'max' and 'min' for accessing '@max' and '@min'
with default values '0' and '-10' respectively.

NEXT to that, I would like to enter 'max' and 'min' as keys into a class
variable '@@properties' to allow me to inspect which properties a
particular instance has. 

	b_props = B.properties	# hash with keys ':max' and ':min'

But creating a class variable in class A would end up having all
properties in ALL inheriting classes. So, the class variable would have
to be installed into the inheriting class.

I hope this makes it more clear.

> 
> Also see the thread(s) from a couple of weeks ago or so on class
> variables.  (See thread at [ruby-talk:19506], and also 19972 and
> 19974, which have to do with adding class variables to an existing
> class hierarchy.)
> 

Will do. Thank you.

Renald