S
Stefano Grioni
Hello,
I'm tying to create a method which would allow me to get and set
instance variables having the same name as the class. And this should be
true even for classes inheriting it.
For instance
At the moment, this code creates "mother" and "mother=" instance methods
for both Mother and Daughter's classes.
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.
Could you help me?
I'm tying to create a method which would allow me to get and set
instance variables having the same name as the class. And this should be
true even for classes inheriting it.
For instance
Code:
class Mother
define_method(self.to_s.downcase){ instance_variable_get
'@'<<self.class.to_s.downcase }
define_method((self.to_s.downcase+'=').to_sym){|nom|
instance_variable_set '@'<<self.class.to_s.downcase, nom}
end
class Daughter < Mother
end
At the moment, this code creates "mother" and "mother=" instance methods
for both Mother and Daughter's classes.
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.
Could you help me?