8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/domain/factory/scalar.rb', line 8
def self.instance_module(component_names)
Module.new{
define_method(:initialize) do |*args|
component_names.zip(args).each do |n,arg|
instance_variable_set(:"@#{n}", arg)
end
end
component_names.each do |n|
define_method(n) do
instance_variable_get(:"@#{n}")
end
end
define_method(:to_hash) do
component_names.each_with_object({}) do |n,h|
h[n] = instance_variable_get(:"@#{n}")
end
end
include Equalizer.new(component_names)
}
end
|