hash_kit 0.5.0 → 0.5.1
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 +4 -4
- data/lib/hash_kit/helper.rb +24 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f90e18ad4471abb39b5b80f89214a258e3621c7
|
4
|
+
data.tar.gz: 9e1abd5eb88d5f1be74db2156e90514da383eda5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44c314d95ef6201e74c315af2149293f119e335fb848c7d845ec95552863a58c7404bda5c71601ea3423ac5521b3c3714ed6e87a41ae0b3cdcd1aea1c134f868
|
7
|
+
data.tar.gz: 786a798cc07e83965e48af4f828b82aebee98aeb99464cefb23290db70541c94c58f933f343a9089dde974c8d45f6a28931175a9ac6f602fae35ba169234a337
|
data/lib/hash_kit/helper.rb
CHANGED
@@ -3,6 +3,10 @@ module HashKit
|
|
3
3
|
|
4
4
|
#This method is called to make a hash allow indifferent access (it will accept both strings & symbols for a valid key).
|
5
5
|
def indifferent!(hash)
|
6
|
+
unless hash.is_a?(Hash)
|
7
|
+
return
|
8
|
+
end
|
9
|
+
|
6
10
|
#set the default proc to allow the key to be either string or symbol if a matching key is found.
|
7
11
|
hash.default_proc = proc do |h, k|
|
8
12
|
if h.key?(k.to_s)
|
@@ -16,14 +20,32 @@ module HashKit
|
|
16
20
|
|
17
21
|
#recursively process any child hashes
|
18
22
|
hash.each do |key,value|
|
19
|
-
if hash[key] != nil
|
20
|
-
|
23
|
+
if hash[key] != nil
|
24
|
+
if hash[key].is_a?(Hash)
|
25
|
+
indifferent!(hash[key])
|
26
|
+
elsif hash[key].is_a?(Array)
|
27
|
+
indifferent_array!(hash[key])
|
28
|
+
end
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
24
32
|
hash
|
25
33
|
end
|
26
34
|
|
35
|
+
def indifferent_array!(array)
|
36
|
+
unless array.is_a?(Array)
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
array.each do |i|
|
41
|
+
if i.is_a?(Hash)
|
42
|
+
indifferent!(i)
|
43
|
+
elsif i.is_a?(Array)
|
44
|
+
indifferent_array!(i)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
27
49
|
#This method is called to convert all the keys of a hash into symbols to allow consistent usage of hashes within your Ruby application.
|
28
50
|
def symbolize(hash)
|
29
51
|
{}.tap do |h|
|