I
Iñaki Baz Castillo
Hi, I've done some custom "field_accessor" (similar to "attr_accessor" but=
=20
with some neccessary difference). It works perfectly if I=20
defined "field_accessor" in the same class:
class Header
def self.field_accessor(name)
module_eval %{ def #{name}() .... end }
end
end
class From < Header
field_accessor :user, :domain
end
But I'd like to have field_accessor definition out of "Header" class, maybe=
in=20
a module but don't get it working. If I do:
module FieldAccessor
module_eval %{ def #{name}() .... end }
end
class From
include FieldAccessor
field_accessor :user, :domain
end
Then I get:
NoMethodError: undefined method `field_accessor' for From:Class
Later I've tryed with the following and it seems to work:
module FieldAccessor
module_eval %{ def #{name}() .... end }
# It also works with "class_eval".
end
class From
extend FieldAccessor
field_accessor :user, :domain
end
So, while I was writting this mail I found the solution, but would like to=
=20
know if it's the correct way. Thanks a lot.
=2D-=20
I=C3=B1aki Baz Castillo
=20
with some neccessary difference). It works perfectly if I=20
defined "field_accessor" in the same class:
class Header
def self.field_accessor(name)
module_eval %{ def #{name}() .... end }
end
end
class From < Header
field_accessor :user, :domain
end
But I'd like to have field_accessor definition out of "Header" class, maybe=
in=20
a module but don't get it working. If I do:
module FieldAccessor
module_eval %{ def #{name}() .... end }
end
class From
include FieldAccessor
field_accessor :user, :domain
end
Then I get:
NoMethodError: undefined method `field_accessor' for From:Class
Later I've tryed with the following and it seems to work:
module FieldAccessor
module_eval %{ def #{name}() .... end }
# It also works with "class_eval".
end
class From
extend FieldAccessor
field_accessor :user, :domain
end
So, while I was writting this mail I found the solution, but would like to=
=20
know if it's the correct way. Thanks a lot.
=2D-=20
I=C3=B1aki Baz Castillo