bindable_block 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/lib/bindable_block/bound_block.rb +1 -1
- data/lib/bindable_block/version.rb +1 -1
- data/lib/bindable_block.rb +5 -14
- data/spec/bindable_block_spec.rb +15 -1
- 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: d7c77727a32c73c77e2cb816d9f880eb0e6a9238
|
4
|
+
data.tar.gz: 7306e61629cd4d2b3c15c186570277c7e1de3f96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60f043e883160d633de196afd83e18685a0594b1681ff07b962ee8776f365c62b8b9cb095195917d68b8d1cafb72c514c441feb48e611bb81ef5790c0279223d
|
7
|
+
data.tar.gz: d1cc88434d59d28c9cd0abb1dcfd9ed6ee11b99ee0e481c5b747051ac86601d7d93624f459b82110b174f1e03b3dfbd2112b9add641aa1f951f7d126d89bd6a8
|
data/lib/bindable_block.rb
CHANGED
@@ -2,9 +2,6 @@ require "bindable_block/version"
|
|
2
2
|
require 'bindable_block/bound_block'
|
3
3
|
|
4
4
|
class BindableBlock < Proc
|
5
|
-
|
6
|
-
# match args to arity, since instance_method has lambda properties
|
7
|
-
|
8
5
|
def initialize(klass=BasicObject, &block)
|
9
6
|
@klass = klass
|
10
7
|
@original_block = block
|
@@ -23,10 +20,6 @@ class BindableBlock < Proc
|
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
|
-
def call(*args, &block)
|
27
|
-
@original_block.call(*args, &block)
|
28
|
-
end
|
29
|
-
|
30
23
|
def arity
|
31
24
|
@original_block.arity
|
32
25
|
end
|
@@ -38,24 +31,22 @@ class BindableBlock < Proc
|
|
38
31
|
klass = @klass
|
39
32
|
|
40
33
|
proc_maker = lambda do |curried_args, uncurried_size|
|
41
|
-
|
34
|
+
curried = Proc.new do |*args, &block|
|
42
35
|
actual_args = curried_args + args
|
43
36
|
if uncurried_size <= actual_args.size
|
44
37
|
original_block.call(*actual_args, &block)
|
45
38
|
else
|
46
|
-
|
47
|
-
bindable_blk_class.new klass, &curried
|
39
|
+
proc_maker.call actual_args, uncurried_size
|
48
40
|
end
|
49
41
|
end
|
50
|
-
|
42
|
+
curried.instance_variable_set :@curried_values, {
|
51
43
|
original_block: original_block,
|
52
44
|
curried_args: curried_args,
|
53
45
|
uncurried_size: arity,
|
54
46
|
}
|
55
|
-
|
47
|
+
bindable_blk_class.new klass, &curried
|
56
48
|
end
|
57
|
-
|
58
|
-
BindableBlock.new klass, &curried
|
49
|
+
proc_maker.call [], arity
|
59
50
|
end
|
60
51
|
|
61
52
|
private
|
data/spec/bindable_block_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe BindableBlock do
|
|
35
35
|
assert_equal 1, BindableBlock.new { @a }.bind(o).call
|
36
36
|
end
|
37
37
|
|
38
|
-
it 'can be
|
38
|
+
it 'can be bound to multiple different objects' do
|
39
39
|
block = BindableBlock.new { name }
|
40
40
|
assert_equal 'Josh', block.bind(klass.new 'Josh').call
|
41
41
|
assert_equal 'Mei', block.bind(klass.new 'Mei').call
|
@@ -169,6 +169,20 @@ describe BindableBlock do
|
|
169
169
|
assert_equal [1, 2, 3, 4, 'Carmen'], b.curry[1, 2].bind(instance).curry[3, &four]
|
170
170
|
assert_equal [1, 2, 3, 4, 'Carmen'], b.curry[1][2].bind(instance).curry[3, &four]
|
171
171
|
assert_equal [1, 2, 3, 4, 'Carmen'], b.curry[1][2].bind(instance).curry[3, &four]
|
172
|
+
|
173
|
+
assert_equal [1, 2, 3, 4, 'Carmen'], b.curry[1].bind(instance)[2][3, &four]
|
174
|
+
assert_equal [1, 2, 3, 4, 'Carmen'], b.curry[1, 2].bind(instance)[3, &four]
|
175
|
+
assert_equal [1, 2, 3, 4, 'Carmen'], b.curry[1][2].bind(instance)[3, &four]
|
176
|
+
assert_equal [1, 2, 3, 4, 'Carmen'], b.curry[1][2].bind(instance)[3, &four]
|
177
|
+
end
|
178
|
+
|
179
|
+
example 'other #curry bullshit' do
|
180
|
+
b = BindableBlock.new { |a, b, c, &d| [a,b,c,d.call, name] }
|
181
|
+
four = lambda { 4 }
|
182
|
+
assert_equal [1, 2, 3, 4, 'Unbound Name'], b.curry[1].call(2).yield(3, &four)
|
183
|
+
assert_equal [1, 2, 3, 4, 'Unbound Name'], b.curry[1].===(2).(3, &four)
|
184
|
+
assert_equal [1, 2, 3, 4, 'Carmen'], b.curry.bind(instance).call(1)[2].yield(3, &four)
|
185
|
+
assert_equal [1, 2, 3, 4, 'Carmen'], b.curry.bind(instance).===(1).(2, 3, &four)
|
172
186
|
end
|
173
187
|
|
174
188
|
example '#hash' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindable_block
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Cheek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|