hash_kit 0.4.9 → 0.5.0
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 +23 -0
- data/lib/hash_kit.rb +1 -0
- 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: 1cda8f2f6c623b14143702e178971f8e32384fff
|
4
|
+
data.tar.gz: 31d76b84f42340ba5a626c907c53c83b24784ad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aa32033e917eba91320285f75f9dce9d2004e5a7ab1d46caa0f475b2b81856b8ec305e7c1c39c05aa8c076c45a46c540d19ec2afefe41414b4c268290501452
|
7
|
+
data.tar.gz: 130846e400f1f182492bf4a52bb2eba6dec664711948be14530427f7658999c78b21a8abcf99e43667fb994efc45f374608752484ef8e708cfa075eb17224102
|
data/lib/hash_kit/helper.rb
CHANGED
@@ -1,6 +1,29 @@
|
|
1
1
|
module HashKit
|
2
2
|
class Helper
|
3
3
|
|
4
|
+
#This method is called to make a hash allow indifferent access (it will accept both strings & symbols for a valid key).
|
5
|
+
def indifferent!(hash)
|
6
|
+
#set the default proc to allow the key to be either string or symbol if a matching key is found.
|
7
|
+
hash.default_proc = proc do |h, k|
|
8
|
+
if h.key?(k.to_s)
|
9
|
+
h[k.to_s]
|
10
|
+
elsif h.key?(k.to_sym)
|
11
|
+
h[k.to_sym]
|
12
|
+
else
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
#recursively process any child hashes
|
18
|
+
hash.each do |key,value|
|
19
|
+
if hash[key] != nil && hash[key].is_a?(Hash)
|
20
|
+
indifferent(hash[key])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
hash
|
25
|
+
end
|
26
|
+
|
4
27
|
#This method is called to convert all the keys of a hash into symbols to allow consistent usage of hashes within your Ruby application.
|
5
28
|
def symbolize(hash)
|
6
29
|
{}.tap do |h|
|
data/lib/hash_kit.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sage One
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|