methods 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/lib/methods/methods_wrapper.rb +6 -5
- data/lib/methods/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1a00020e759e6a949a08c27b12700d4746866d6
|
4
|
+
data.tar.gz: e628b64ebddf574c8e13dc3dc5b76a7d6439896d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25b4fb3b3423c2c2ee7587fec06a3518afbc38e4dc0bf839a2ded2201936d3a046cb6ae6f789f1d12ccd9a362b217ae123ae94dc2665a222976a8605e1a41261
|
7
|
+
data.tar.gz: 02c8da5e16fd73fd6a5b415b7d41e201c7297d778a9ab2b67e090631af1375c557ec93eb79c8423985c52d7ca8afa39c73210f25ff3400839f044f6a23115672
|
data/README.md
CHANGED
@@ -73,6 +73,23 @@ irb(main):014:0> [1,2,3].map(&method.adder(1, c: 5))
|
|
73
73
|
=> [7, 8, 9]
|
74
74
|
```
|
75
75
|
|
76
|
+
Block currying
|
77
|
+
|
78
|
+
```
|
79
|
+
irb(main):001:0> def add_to_block(a)
|
80
|
+
irb(main):002:1> a + yield
|
81
|
+
irb(main):003:1> end
|
82
|
+
=> :add_to_block
|
83
|
+
irb(main):004:0> add_two = method.add_to_block { 2 }
|
84
|
+
=> #<Proc:0x007f91a8013290@/Users/sevos/Projects/methods/lib/methods/methods_wrapper.rb:14 (lambda)>
|
85
|
+
irb(main):005:0> [1,2,3].map(&add_two)
|
86
|
+
=> [3, 4, 5]
|
87
|
+
irb(main):006:0> add_two.call(3) { 5 }
|
88
|
+
=> 8
|
89
|
+
irb(main):007:0> add_two.call(3)
|
90
|
+
=> 5
|
91
|
+
```
|
92
|
+
|
76
93
|
## Development
|
77
94
|
|
78
95
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -4,19 +4,20 @@ module Methods
|
|
4
4
|
@obj = obj
|
5
5
|
end
|
6
6
|
|
7
|
-
def method_missing(method, *args, **kwargs)
|
7
|
+
def method_missing(method, *args, **kwargs, &block)
|
8
8
|
__raise_no_method_error(method) unless respond_to?(method)
|
9
9
|
method = @obj.method(method)
|
10
10
|
|
11
|
-
if args.empty? && kwargs.empty?
|
11
|
+
if args.empty? && kwargs.empty? && block.nil?
|
12
12
|
method
|
13
13
|
else
|
14
|
-
::Kernel.lambda do |*call_args, **call_kwargs|
|
14
|
+
::Kernel.lambda do |*call_args, **call_kwargs, &call_block|
|
15
15
|
merged_kwargs = kwargs.merge(**call_kwargs)
|
16
|
+
merged_block = call_block || block
|
16
17
|
if merged_kwargs.empty?
|
17
|
-
method.call(*args, *call_args)
|
18
|
+
method.call(*args, *call_args, &merged_block)
|
18
19
|
else
|
19
|
-
method.call(*args, *call_args, **merged_kwargs)
|
20
|
+
method.call(*args, *call_args, **merged_kwargs, &merged_block)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
data/lib/methods/version.rb
CHANGED