> L?hett?j?: nobu.nokada / softhome.net
> Aihe: Re: Creating objects from a template
> 
> Hi,
> 
> At Wed, 9 Feb 2005 15:20:07 +0900,
> David McCabe wrote in [ruby-talk:130214]:
> > In python, my parser returns a hash of unit_type objects, where the
> > names of units are the keys. Each time a unit is instantiated, it
> > receives a unit_type object as an argument. Now here's the interesting
> > part: it copies the instance variables from the unit_type into itself.
> > 
> > class Unit(object):
> >       def __init__(self, type):
> > 	  self.type = type
> > 	  self.__dict__.update(self.type.__dict__)
> > 
> > There's more to it than that, but that's the interesting part. So now
> > I can say:
> > 
> >       my_new_unit = Unit(types["Panzer"])
> > 
> > And I'll get a Unit object with all the values for Panzers
> > initialized.
> 
> What about:
> 
>   module Unit
>   end
> 
>   my_new_unit = types["Panzer"].new.extend(Unit) # As later

I thought #extend only works for instance methods, not variables? 

Presumably it'd be OK if Unit defined accessors for all its IVs, 
but then those wouldn't have initial values (unless one built them
in the accessors...)

> -- 
> Nobu Nakada

E