From: Stefano Grioni Date: 2009-07-21T21:20:01+09:00 Subject: Re: Inheritance problem with dynamic methods David A. Black wrote: > Hi -- > > On Tue, 21 Jul 2009, Stefano Grioni wrote: > >> define_method(self.to_s.downcase){ instance_variable_get >> Instead, what I'd like to have in a "mother" and "mother=" instance >> methods for Mother, and "daughter" and "daughter=" for Daughter. >> >> I think that there is some meta programming trick that I'm missing but I >> can't find which one. > > One metaprogramming trick you could use is attr_accessor :-) Another > is the "inherited" hook. Try this: > > class Mother > def self.attr_eponymous(c=self) > c.send(:attr_accessor, c.to_s.downcase) > end > > def self.inherited(c) > attr_eponymous(c) > end > > attr_eponymous > end > > > David Hi, Your solution is brilliant :D I must admit that I was so sure that the solution would come of some weird twist of a singleton method that I completely skipped the "inherited" hook ... Thanks a lot! -- Posted via http://www.ruby-forum.com/.