Module: Erector::AfterInitialize::ClassMethods

Defined in:
lib/erector/after_initialize.rb

Instance Method Summary collapse

Instance Method Details

#after_initialize(instance = nil, &blk) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/erector/after_initialize.rb', line 8

def after_initialize(instance=nil, &blk)
  if blk
    after_initialize_parts << blk
  elsif instance
    if superclass.respond_to?(:after_initialize)
      superclass.after_initialize instance
    end
    after_initialize_parts.each do |part|
      instance.instance_eval &part
    end
  else
    raise ArgumentError, "You must provide either an instance or a block"
  end
end