bindable_block 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7c77727a32c73c77e2cb816d9f880eb0e6a9238
4
- data.tar.gz: 7306e61629cd4d2b3c15c186570277c7e1de3f96
3
+ metadata.gz: c79f870c878cce27cb2c3ebe6bc6a81e838d720c
4
+ data.tar.gz: 409d6ae7734c8e743b677227b24a65aeb5b6d387
5
5
  SHA512:
6
- metadata.gz: 60f043e883160d633de196afd83e18685a0594b1681ff07b962ee8776f365c62b8b9cb095195917d68b8d1cafb72c514c441feb48e611bb81ef5790c0279223d
7
- data.tar.gz: d1cc88434d59d28c9cd0abb1dcfd9ed6ee11b99ee0e481c5b747051ac86601d7d93624f459b82110b174f1e03b3dfbd2112b9add641aa1f951f7d126d89bd6a8
6
+ metadata.gz: 89f99c351e8ae5bb66fba648ddd2c68ec67d834ee695d1ce6101c59829c996bfe82f77ed9e4ba664818ee6c608bbcde1db8f88b35ee900a5c5393907dfd9e90c
7
+ data.tar.gz: a581a80af2193ce3e7fbde373340e279053319f1ce3b9bfa0b643e6775364afee15dca7dbc499e630920904495a3040d5aaf0b278315716dcf8635672e64c44c
@@ -14,7 +14,7 @@ class BindableBlock < Proc
14
14
  end
15
15
 
16
16
  def bind(target)
17
- bound = BoundBlock.new @original_block, &@instance_method.bind(target)
17
+ bound = BoundBlock.new @original_block, target, &@instance_method.bind(target)
18
18
  if @curried_args then bound.curry(@uncurried_size)[*@curried_args]
19
19
  else bound
20
20
  end
@@ -2,12 +2,13 @@ require 'bindable_block/arg_aligner'
2
2
 
3
3
  class BindableBlock < Proc
4
4
  class BoundBlock < Proc
5
- def initialize(original_block, &method)
5
+ def initialize(original_block, target, &method)
6
6
  f, ln, * = caller[2].split(':')
7
7
  self.bound_file = f
8
8
  self.bound_line_number = ln.to_i
9
9
  self.original_block = original_block
10
10
  self.method = method
11
+ self.target = target
11
12
  end
12
13
 
13
14
  def call(*args, &block)
@@ -31,6 +32,11 @@ class BindableBlock < Proc
31
32
  end
32
33
  alias to_s inspect
33
34
 
35
+ def hash
36
+ target_hash = target.hash rescue 0
37
+ target_hash ^ original_block.hash
38
+ end
39
+
34
40
 
35
41
  def binding
36
42
  raise NotImplementedError, <<-SADFACE.gsub(/^\s*/, '')
@@ -48,7 +54,7 @@ class BindableBlock < Proc
48
54
 
49
55
  private
50
56
 
51
- attr_accessor :bound_file, :bound_line_number, :original_block, :method
57
+ attr_accessor :bound_file, :bound_line_number, :original_block, :method, :target
52
58
 
53
59
  def align(args)
54
60
  if original_block.lambda?
@@ -1,3 +1,3 @@
1
1
  class BindableBlock < Proc
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -1,7 +1,5 @@
1
1
  require 'bindable_block'
2
2
 
3
- # TODO: when created with a lambda, args should match like lambda args
4
-
5
3
  describe BindableBlock do
6
4
  let(:name) { 'Unbound Name' }
7
5
  let(:default_name) { "Carmen" }
@@ -12,6 +10,9 @@ describe BindableBlock do
12
10
  def assert_equal(a, b)
13
11
  expect(b).to eq a
14
12
  end
13
+ def refute_equal(a, b)
14
+ expect(b).to_not eq a
15
+ end
15
16
  def assert_same(a, b)
16
17
  expect(b).to equal a
17
18
  end
@@ -185,8 +186,44 @@ describe BindableBlock do
185
186
  assert_equal [1, 2, 3, 4, 'Carmen'], b.curry.bind(instance).===(1).(2, 3, &four)
186
187
  end
187
188
 
188
- example '#hash' do
189
- raise pending 'punting on this, b/c I really don\'t know what it should do here'
189
+ describe '#hash' do
190
+ context 'when unbound' do
191
+ it 'delegates the hash to its proc' do
192
+ p = Proc.new {}
193
+ assert_equal p.hash, BindableBlock.new(&p).hash
194
+ end
195
+ # something about curry?
196
+ end
197
+
198
+ context 'when bound' do
199
+ let(:p) { lambda {} }
200
+ let(:unbound) { BindableBlock.new(&p) }
201
+
202
+ it 'is an integer' do
203
+ expect(unbound.bind(instance).hash).to be_a_kind_of Integer
204
+ end
205
+
206
+ it 'gives a different hash than the unbound version' do
207
+ refute_equal p.hash, unbound.bind(instance).hash
208
+ end
209
+
210
+ it 'gives the same hash when bound to an object with the same hash' do
211
+ o = Object.new
212
+ assert_equal unbound.bind(o).hash,
213
+ unbound.bind(o).hash
214
+ end
215
+
216
+ it 'gives a different hash when bound to an object with a different hash' do
217
+ o1 = Object.new
218
+ o2 = Object.new
219
+ refute_equal unbound.bind(o1).hash, unbound.bind(o2).hash
220
+ end
221
+
222
+ it 'gives the same hash when bound to an object without a hash' do
223
+ assert_equal unbound.bind(BasicObject.new).hash,
224
+ unbound.bind(BasicObject.new).hash
225
+ end
226
+ end
190
227
  end
191
228
 
192
229
  example '#lambda?' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bindable_block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cheek