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.
- checksums.yaml +4 -4
- data/lib/hash/as/tree.rb +11 -8
- 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: 37babe62e55cad9f2355c7a18268e1194e36ae59
|
4
|
+
data.tar.gz: 3a96690e8288a4f0220751c15457012a8f6fe9e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73369a340c67153fce37d090a1583cb28d95800aa477717346a74f082619dd8d8b244057afcbbff666efd6aa17e5d833ce6ad2bdf91d1baa057c162eea8dd469
|
7
|
+
data.tar.gz: 25388124b5d2d13f590f7a1986b669467463d4d833854aed7acd767666a4ec89258101b9bfeed8a1301685821a35b594be845d44fc4c46da69da54ddbf99eb58
|
data/lib/hash/as/tree.rb
CHANGED
@@ -9,10 +9,9 @@ class Hash
|
|
9
9
|
|
10
10
|
refine Hash do
|
11
11
|
def traverse
|
12
|
-
return to_enum
|
12
|
+
return to_enum __method__ unless block_given?
|
13
13
|
|
14
|
-
nodes =
|
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
|
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
|
+
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-
|
11
|
+
date: 2017-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: to_proc
|