C
Chris Richards
I have created a module as follows which adds an initialize method to
the class it is included in. The problem is that the initializer method
could be easily overriden by the includer Class. Is there a way to
ensure that the initialize method is run even though it may have been
overriden??
module SomeModule
def self.included(base)
base.class_eval do
attr_accessor :fields, :x_position, :y_position
def initialize(x_position=0, y_position=0)
@fields=self.class.xfields.clone
self.y_position=y_position
self.x_position=x_position
for field in @fields
eval "self."+field[:var] + " = field[:value]"
end
@fields = @fields.sort_by{|f| f[
rder]} if @fields.find{|f|
f[
rder]}
end
end
end
end
Any help is appreciated.
Thanks, Chris
the class it is included in. The problem is that the initializer method
could be easily overriden by the includer Class. Is there a way to
ensure that the initialize method is run even though it may have been
overriden??
module SomeModule
def self.included(base)
base.class_eval do
attr_accessor :fields, :x_position, :y_position
def initialize(x_position=0, y_position=0)
@fields=self.class.xfields.clone
self.y_position=y_position
self.x_position=x_position
for field in @fields
eval "self."+field[:var] + " = field[:value]"
end
@fields = @fields.sort_by{|f| f[
f[
end
end
end
end
Any help is appreciated.
Thanks, Chris