hash-as-tree 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hash/as/tree.rb +11 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd7dc34f2a588ef21cc27402c1a2f1b1f26a03f0
4
- data.tar.gz: 0e99b251cc97535c93ad43fff06beffd45dfcd19
3
+ metadata.gz: 37babe62e55cad9f2355c7a18268e1194e36ae59
4
+ data.tar.gz: 3a96690e8288a4f0220751c15457012a8f6fe9e3
5
5
  SHA512:
6
- metadata.gz: 035ba398bb143a3983003e8b51d9624c03fb5bcc7606b4fbc2e5e07056f77a1b3bb33d8123f072c3d62b25cf4122f6487c03686ee090c86bed60706a0cfaf628
7
- data.tar.gz: bf728a6e41563a8e949a71df93db950c2cf29cc3d9bfa6e14ad5ae4de24ddcb412f04182167fbfb84082c738ccf69ed3150111a50ae0122634388ffb7aea0bfe
6
+ metadata.gz: 73369a340c67153fce37d090a1583cb28d95800aa477717346a74f082619dd8d8b244057afcbbff666efd6aa17e5d833ce6ad2bdf91d1baa057c162eea8dd469
7
+ data.tar.gz: 25388124b5d2d13f590f7a1986b669467463d4d833854aed7acd767666a4ec89258101b9bfeed8a1301685821a35b594be845d44fc4c46da69da54ddbf99eb58
@@ -9,10 +9,9 @@ class Hash
9
9
 
10
10
  refine Hash do
11
11
  def traverse
12
- return to_enum(__method__) unless block_given?
12
+ return to_enum __method__ unless block_given?
13
13
 
14
- nodes = Queue.new
15
- nodes.push Node.new value: self
14
+ nodes = initialize_nodes
16
15
 
17
16
  until nodes.empty?
18
17
  current_node = nodes.pop
@@ -25,10 +24,7 @@ class Hash
25
24
  hash = dup
26
25
  hash.default_proc = COMBINATOR
27
26
 
28
- nodes, root_node = Queue.new, (Node.new value: self)
29
- each do |key, value|
30
- nodes.push Node.new key: key, value: value, parent: root_node
31
- end
27
+ nodes = initialize_nodes
32
28
 
33
29
  until nodes.empty?
34
30
  passed_node = nodes.pop
@@ -44,13 +40,20 @@ class Hash
44
40
  hash.dig *path
45
41
  end
46
42
  cursor[returned_node.key] = returned_node.value
47
- returned_node.children.each &[nodes, :push]
48
43
  end
49
44
  end
50
45
 
51
46
  hash.default_proc = default_proc
52
47
  hash
53
48
  end
49
+
50
+ def initialize_nodes
51
+ nodes, root_node = Queue.new, (Node.new value: self)
52
+ each do |key, value|
53
+ nodes.push Node.new key: key, value: value, parent: root_node
54
+ end
55
+ nodes
56
+ end
54
57
  end
55
58
 
56
59
  class Node
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash-as-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-14 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: to_proc