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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b5c3db6585a5f5441879deead1ad9654e76dd2c
4
- data.tar.gz: 2da240169ae947e46bf26b9b7f65b0ee0322d165
3
+ metadata.gz: f1a00020e759e6a949a08c27b12700d4746866d6
4
+ data.tar.gz: e628b64ebddf574c8e13dc3dc5b76a7d6439896d
5
5
  SHA512:
6
- metadata.gz: 687b9f065eddf80c3752bc4dc3c541e205fe23d719de2ae641e120c56359dc4378d0e0c077005b72035a4600c9535482e94b3d05c88edfcbf51ad722c74bfee6
7
- data.tar.gz: e33b47bedfa649375460547c4877eda94d8368c84ba63480f88379552cc8fb13be3629ba173626c8fb0a0a803a8a523eea3e4a9ae930467bb12bc44c13a0a30d
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
@@ -1,3 +1,3 @@
1
1
  module Methods
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: methods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Roszczyk