Module: Preinitializable::Meta

Defined in:
lib/mixers/preinitialize.rb

Instance Method Summary collapse

Instance Method Details

#new(*args, &blk) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/mixers/preinitialize.rb', line 72

def new(*args, &blk)
  o = allocate
  #if respond_to?(:default_instance_variables)
  #  default_instance_variables.each{|k,v| o.instance_variable_set( "@#{k.to_s.gsub(/\W$/,'')}",v )}
  #end
  a = ancestors
  until a.empty?
    m = a.pop
    if m.private_instance_methods(false).include?('preinitialize') or
         m.protected_instance_methods(false).include?('preinitialize') or
           m.public_instance_methods(false).include?('preinitialize')
      im = instance_method('preinitialize')
      im.arity == 0 ? im.bind(o).call : im.bind(o).call(*args, &blk)
    end
  end
  o.__send__(:initialize, *args, &blk) if o.class.private_method_defined?(:initialize)
  o
end