Class: Object

Inherits:
BasicObject
Defined in:
lib/subtle/param_constructor.rb

Instance Method Summary collapse

Instance Method Details

#param_constructor(&block_for_each) ⇒ Object Also known as: params_constructor



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/subtle/param_constructor.rb', line 2

def param_constructor(&block_for_each)
  self.class_eval('
  def initialize(params={}, &block)
    params.each do |attr, value|
      self.send("#{attr}=", value)
    end if params
    unless block.nil?
      block.call(self)
    end
    constructor_method if respond_to?(:constructor_method)
    block.call(self) if block
  end')
  unless block_for_each.nil?
    self.send(:define_method, :constructor_method, &block_for_each)
  end
end