36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/instantiator.rb', line 36
def instantiate
if Instantiator.unsupported_class?(self)
raise Error.new("#{self}.instantiate is not yet supported")
end
if singleton_methods(false).map(&:to_sym).include?(:new)
arity = method(:new).arity
else
arity = instance_method(:initialize).arity
end
numbers_of_parameters = arity >= 0 ? [arity] : (-(arity + 1)..5-(arity + 1)).to_a
instance = nil
numbers_of_parameters.each do |number_of_parameters|
begin
instance = new(*Array.new(number_of_parameters) { MethodInvocationSink.new })
return instance if instance
rescue ArgumentError => e
end
end
raise Error.new("Unable to instantiate #{self}")
end
|