multi_hash_iterator 0.1.0 → 0.1.1

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: d7fd2cda2d252b6ceabca391554623650693b922
4
- data.tar.gz: 8a75902056eab48087f7ce9376cd2b3dce1d6f5a
3
+ metadata.gz: 88ea9612ce4415bb7a612f00af4edcec6edf2a6c
4
+ data.tar.gz: 688f2342d86cad7c69f1f3ae2aeab36f4ae4cf75
5
5
  SHA512:
6
- metadata.gz: a6956f72d5bbb6cc44be93e5512efbdd7448240e913d80dc62d94114943b724d1a950abc0b31a7e06d55b33c24984874fbf87316cb059adca7dfe6fcb46dbaff
7
- data.tar.gz: 9359f88330097077caa3eb4c87cd1f9591f60b1e0608444792d9cda026f1e9a53640f5f2c0fbbb337676ecfc32609a7372bce80d23ad6c5b9a33139b8fb551ac
6
+ metadata.gz: b15ea5786196b6a2f58643440442fc80a91fb679aab9092d841c013b50e5aa151ba70b86ca29921b384a6035a43e47f686315e5ed79532acab7022f3795a2d28
7
+ data.tar.gz: ae72986870f7e74381a8b827bce6695afc142d936895f4ed2654ac019f5a065a9de03f0d6c47c63248b7e3e2c8e79b545d21aaa0a08e2cbcebaab1b2bf5da511
@@ -6,7 +6,6 @@ class MultiHash
6
6
 
7
7
  def initialize *hashes
8
8
  @hashes = hashes
9
- @final_hash = {}
10
9
  end
11
10
 
12
11
  # Enumerate for each key.
@@ -15,10 +14,11 @@ class MultiHash
15
14
  def each
16
15
  return enum_for(:each) unless block_given?
17
16
 
17
+ final_hash = {}
18
18
  count = @hashes.length
19
19
  count.times do |i|
20
20
  @hashes[i].each do |key, v|
21
- next if @final_hash[key]
21
+ next if final_hash[key]
22
22
 
23
23
  values = [].fill(nil, 0, i)
24
24
  values << v
@@ -27,7 +27,7 @@ class MultiHash
27
27
  end
28
28
 
29
29
  yield key, values if block_given?
30
- @final_hash[key] = values
30
+ final_hash[key] = values
31
31
  end
32
32
  end
33
33
  end
@@ -2,7 +2,7 @@ require './lib/multi_hash_iterator'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "multi_hash_iterator"
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
  s.authors = ["Albert Tedja"]
7
7
  s.email = "nicho_tedja@yahoo.com"
8
8
  s.homepage = "https://github.com/atedja/multi_hash_iterator"
data/test/helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './lib/multi-hash-iterator.rb'
1
+ require './lib/multi_hash_iterator.rb'
2
2
 
3
3
  require 'minitest/autorun'
4
4
  require 'minitest/unit'
@@ -28,6 +28,25 @@ class TestMultiHashIterator < Minitest::Test
28
28
  end
29
29
 
30
30
 
31
+ def test_basic
32
+ h1 = { a: 1, b: 2, c: 3 }
33
+ h2 = { a: 2, b: 3 }
34
+ h3 = { b: 4, d: 6 }
35
+ mh = MultiHash.new(h1, h2, h3)
36
+
37
+ iteration = 0
38
+ mh.each do |k, v|
39
+ iteration += 1
40
+ end
41
+
42
+ mh.each do |k, v|
43
+ iteration += 1
44
+ end
45
+
46
+ assert_equal 8, iteration
47
+ end
48
+
49
+
31
50
  def test_compound_values
32
51
  h1 = { a: 1, b: 2, c: [100, 200] }
33
52
  h2 = { a: 2, b: "foo" }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_hash_iterator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Tedja