flat_keys 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/flat_keys/version.rb +1 -1
- data/lib/flat_keys.rb +12 -12
- metadata +1 -1
data/lib/flat_keys/version.rb
CHANGED
data/lib/flat_keys.rb
CHANGED
@@ -1,18 +1,6 @@
|
|
1
1
|
require_relative "flat_keys/version"
|
2
2
|
|
3
3
|
class Hash
|
4
|
-
|
5
|
-
def visit_flat_keys(hash, prefix, separator)
|
6
|
-
self.each do |k, v|
|
7
|
-
key = "#{prefix}#{k}"
|
8
|
-
if v.is_a?(Hash)
|
9
|
-
v.visit_flat_keys(hash, "#{key}#{separator}", separator)
|
10
|
-
else
|
11
|
-
hash[key] = v
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
4
|
def flat_keys(separator = ".")
|
17
5
|
hash = {}
|
18
6
|
visit_flat_keys(hash, "", separator)
|
@@ -37,5 +25,17 @@ class Hash
|
|
37
25
|
hash
|
38
26
|
end
|
39
27
|
|
28
|
+
protected
|
29
|
+
|
30
|
+
def visit_flat_keys(hash, prefix, separator)
|
31
|
+
self.each do |k, v|
|
32
|
+
key = "#{prefix}#{k}"
|
33
|
+
if v.is_a?(Hash)
|
34
|
+
v.visit_flat_keys(hash, "#{key}#{separator}", separator)
|
35
|
+
else
|
36
|
+
hash[key] = v
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
40
|
end
|
41
41
|
|