bindable_block 0.0.7 → 0.0.8

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: 5b1c8b49ff2472deebf4c6d9e551166d037b1b8a
4
- data.tar.gz: df827455f3cd67f49550b331849fcda641ca48d3
3
+ metadata.gz: d7c77727a32c73c77e2cb816d9f880eb0e6a9238
4
+ data.tar.gz: 7306e61629cd4d2b3c15c186570277c7e1de3f96
5
5
  SHA512:
6
- metadata.gz: fe81548ae86dc946d2dbe42c3f21ecf9401877eabbec57a1da4183456dc46bc6d7a629f14b3be2c76bfeb47df1e253f39f49a163f388434157173612e8c4a653
7
- data.tar.gz: 30b47e2b53ab657136bead810544a145b1d57b25235ff31256b7fe9458068319a01bd2821a47576de54b8ae79cad29f2fbd47532e8c2c37c0bf098b55b9a0112
6
+ metadata.gz: 60f043e883160d633de196afd83e18685a0594b1681ff07b962ee8776f365c62b8b9cb095195917d68b8d1cafb72c514c441feb48e611bb81ef5790c0279223d
7
+ data.tar.gz: d1cc88434d59d28c9cd0abb1dcfd9ed6ee11b99ee0e481c5b747051ac86601d7d93624f459b82110b174f1e03b3dfbd2112b9add641aa1f951f7d126d89bd6a8
@@ -11,7 +11,7 @@ class BindableBlock < Proc
11
11
  end
12
12
 
13
13
  def call(*args, &block)
14
- method.call(*align(args), &block)
14
+ method.call(*align(args), &block) # match args to arity, since instance_method has lambda properties
15
15
  end
16
16
 
17
17
  def lambda?
@@ -1,3 +1,3 @@
1
1
  class BindableBlock < Proc
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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
- p = Proc.new do |*args, &block|
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
- curried = proc_maker.call actual_args, uncurried_size
47
- bindable_blk_class.new klass, &curried
39
+ proc_maker.call actual_args, uncurried_size
48
40
  end
49
41
  end
50
- p.instance_variable_set :@curried_values, {
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
- p
47
+ bindable_blk_class.new klass, &curried
56
48
  end
57
- curried = proc_maker.call [], arity
58
- BindableBlock.new klass, &curried
49
+ proc_maker.call [], arity
59
50
  end
60
51
 
61
52
  private
@@ -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 rebound' do
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.7
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-10 00:00:00.000000000 Z
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec