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 +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG +3 -0
- data/lib/method_struct.rb +4 -4
- data/lib/method_struct/version.rb +1 -1
- data/spec/method_struct_spec.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0b38691d962c63d8ebb037565c81361f44f3b2b
|
4
|
+
data.tar.gz: f3bcf9cf908e6ead363a94ef5fb954ce88f3dbd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cfec0c5eb4782d6455bf98273b1225c69810197f097f4a37d1e58690f9b5e7844fee9de430c4fc9837cc9ee2cf275a04553b983dfe7247b7749678b6f10288c
|
7
|
+
data.tar.gz: fb802dde5e883e65fe7ccb69a9b589b1ab9efaeaa05643f395ae9a41195e3511e119536a94da2630453cdefeec8feef9506d07e5d44b32a81350bba7566329d6
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
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|
|
data/spec/method_struct_spec.rb
CHANGED
@@ -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
|
+
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-
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|