Iñaki Baz Castillo
4/29/2008 11:27:00 PM
El Mi=C3=A9rcoles, 30 de Abril de 2008, David A. Black escribi=C3=B3:
> The last two definitions of FieldAccessor look wrong; you haven't
> defined the field_accessor method. But assuming that you correct that,
> then yes, extending your class is the best way.
Yes, sorry, what I did is:
module FieldAccessor
def self.field_accessor(name)
module_eval %{ def #{name}() .... end }
# It also works with "class_eval".
end
end
class From
extend FieldAccessor
field_accessor :user, :domain
end
> To answer the question in your subject line: attr_accessor is an
> instance method of Module. That's why all modules and classes can call
> it. You could add field_accessor to Module, but extend is cleaner.
Nice to know, so I was in the good way ;)
Thanks a lot for your help.
=2D-=20
I=C3=B1aki Baz Castillo