Module: Domain::Scalar

Defined in:
lib/domain/factory/scalar.rb

Class Method Summary collapse

Class Method Details

.instance_module(component_names) ⇒ Object



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

.new(*component_names) ⇒ Object



4
5
6
# File 'lib/domain/factory/scalar.rb', line 4

def self.new(*component_names)
  DomainFactory.factor [], instance_module(component_names)
end