instantiator 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/instantiator.rb CHANGED
@@ -3,10 +3,15 @@ require "blankslate"
3
3
 
4
4
  module Instantiator
5
5
 
6
+ class InstantiationError < StandardError; end
7
+
6
8
  class MethodInvocationSink < ::BlankSlate
7
- def method_missing(*args, &block)
9
+ def method_missing(method_name, *args, &block)
8
10
  MethodInvocationSink.new
9
11
  end
12
+ def to_str
13
+ String.new
14
+ end
10
15
  end
11
16
 
12
17
  module ClassMethods
@@ -16,8 +21,17 @@ module Instantiator
16
21
  else
17
22
  arity = instance_method(:initialize).arity
18
23
  end
19
- number_of_parameters = arity >= 0 ? arity : -(arity + 1)
20
- new(*Array.new(number_of_parameters) { MethodInvocationSink.new })
24
+ numbers_of_parameters = arity >= 0 ? [arity] : (-(arity + 1)..5-(arity + 1)).to_a
25
+ instance = nil
26
+ numbers_of_parameters.each do |number_of_parameters|
27
+ begin
28
+ instance = new(*Array.new(number_of_parameters) { MethodInvocationSink.new })
29
+ return instance if instance
30
+ rescue ArgumentError => e
31
+ ensure
32
+ end
33
+ end
34
+ raise InstantiationError.new("Unable to instantiate #{self}")
21
35
  end
22
36
  end
23
37
  end
@@ -1,3 +1,3 @@
1
1
  module Instantiator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -192,4 +192,9 @@ class InstantiatorTest < Test::Unit::TestCase
192
192
  assert_equal klass, instance.class
193
193
  end
194
194
 
195
+ def test_should_instantiate_class_which_defines_its_own_native_new_method_with_some_required_parameters_and_some_optional
196
+ require "strscan"
197
+ instance = StringScanner.instantiate
198
+ end
199
+
195
200
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instantiator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Mead
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-27 00:00:00 +01:00
18
+ date: 2011-07-29 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency