Module: Command

Defined in:
lib/trade-o-matic/command.rb

Class Method Summary collapse

Class Method Details

.new(*_attributes) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/trade-o-matic/command.rb', line 2

def self.new(*_attributes)
  attr_names = []
  attr_defaults = {}

  _attributes.each do |att|
    if att.is_a? Hash
      attr_defaults.merge att
      attr_names += att.keys
    else
      attr_names << att
    end
  end

  Struct.new(*attr_names) do
    define_method(:initialize) do |kwargs={}|
      kwargs = attr_defaults.merge kwargs
      attr_values = attr_names.map { |a| kwargs[a] }
      super(*attr_values)
    end

    define_method(:perform) {}
  end
end