method_struct 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82a0931189bb64b7c53fc5914fa2035fdab4c6e5
4
- data.tar.gz: bbc9dbaa367c4234e1c61c970f5dbd4dbbc1861d
3
+ metadata.gz: e0b38691d962c63d8ebb037565c81361f44f3b2b
4
+ data.tar.gz: f3bcf9cf908e6ead363a94ef5fb954ce88f3dbd1
5
5
  SHA512:
6
- metadata.gz: fe1130865b30c4d0b0c44378c701330ee9981cfbd8e33c566ccc22acfdb571fd9897be82ebaf676ee9e57e337f1e5cf80dc52ac11287027b268731e541ce809d
7
- data.tar.gz: 1dff59c75e2c06d180e035990e0de4c872ea452370f0fbd8487549c9dbd04771707f8a871febf68dbcb94230f15126ed8ca4ced668ca2c1ca6f542e96eb0b1d9
6
+ metadata.gz: 6cfec0c5eb4782d6455bf98273b1225c69810197f097f4a37d1e58690f9b5e7844fee9de430c4fc9837cc9ee2cf275a04553b983dfe7247b7749678b6f10288c
7
+ data.tar.gz: fb802dde5e883e65fe7ccb69a9b589b1ab9efaeaa05643f395ae9a41195e3511e119536a94da2630453cdefeec8feef9506d07e5d44b32a81350bba7566329d6
data/.travis.yml CHANGED
@@ -6,7 +6,6 @@ rvm:
6
6
  - 1.9.3
7
7
  - jruby-18mode
8
8
  - jruby-19mode
9
- - rbx
10
9
  - 1.8.7
11
10
  - ree
12
11
  script: "bundle exec rspec"
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 0.1.5
2
+ + Support blocks
3
+
1
4
  0.1.4
2
5
  ~ Implement [] with a method instead of an alias to make mocks not care which
3
6
  one is called
data/lib/method_struct.rb CHANGED
@@ -13,8 +13,8 @@ module MethodStruct
13
13
  singleton_class = (class << self; self; end)
14
14
 
15
15
  singleton_class.instance_eval do
16
- define_method(method_name) do |*field_values|
17
- new(*field_values).send(method_name)
16
+ define_method(method_name) do |*field_values, &blk|
17
+ new(*field_values).send(method_name, &blk)
18
18
  end
19
19
 
20
20
  define_method(:[]) do |*args|
@@ -22,8 +22,8 @@ module MethodStruct
22
22
  end
23
23
  end
24
24
 
25
- define_method(:[]) do
26
- send(method_name)
25
+ define_method(:[]) do |&blk|
26
+ send(method_name, &blk)
27
27
  end
28
28
 
29
29
  define_method(:initialize) do |*values|
@@ -1,3 +1,3 @@
1
1
  module MethodStruct
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -49,6 +49,28 @@ describe MethodStruct do
49
49
  poker.something(argument1, argument2)
50
50
  end
51
51
 
52
+ context "when method includes block" do
53
+ def create_yielder
54
+ Class.new(MethodStruct.new(:x, :y)) do
55
+ define_method(:call) do |&block|
56
+ block.call(x, y)
57
+ end
58
+ end
59
+ end
60
+
61
+ it "yields to block in class method" do
62
+ expect(create_yielder.call(1, 2){ |x, y| x + y }).to eq(3)
63
+ end
64
+
65
+ it "yields to block in instance method" do
66
+ expect(create_yielder.new(1, 2).call{ |x, y| x + y }).to eq(3)
67
+ end
68
+
69
+ it "yields to block in instance [] version of the call method" do
70
+ expect(create_yielder.new(:x => 1, :y => 2).[]{ |x, y| x + y }).to eq(3)
71
+ end
72
+ end
73
+
52
74
  it "allows for additional methods defined with a block" do
53
75
  klass = MethodStruct.new(:x) do
54
76
  def something
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Obrok
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-21 00:00:00.000000000 Z
11
+ date: 2014-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler