simply_useful 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION.yml +1 -1
- data/lib/core_ext/hash.rb +12 -5
- data/simply_useful.gemspec +1 -1
- data/spec/core_ext/hash_spec.rb +7 -0
- metadata +2 -2
data/.gitignore
CHANGED
data/VERSION.yml
CHANGED
data/lib/core_ext/hash.rb
CHANGED
@@ -25,12 +25,19 @@ module SimplyUseful
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def _deep_symbolize_keys(value)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
if value.is_a? Hash
|
29
|
+
hash = value.inject({}) do |memo,(k,v)|
|
30
|
+
memo[(k.to_sym rescue k)|| k] = _deep_symbolize_keys(v)
|
31
|
+
memo
|
32
|
+
end
|
33
|
+
return hash
|
34
|
+
elsif value.is_a? Array
|
35
|
+
value.map do |e|
|
36
|
+
_deep_symbolize_keys(e)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
value
|
32
40
|
end
|
33
|
-
return hash
|
34
41
|
end
|
35
42
|
|
36
43
|
end
|
data/simply_useful.gemspec
CHANGED
data/spec/core_ext/hash_spec.rb
CHANGED
@@ -17,6 +17,13 @@ describe SimplyUseful::CoreExtensions::Keys do
|
|
17
17
|
te = {:a => {:b => "c"}}
|
18
18
|
te.should == ta
|
19
19
|
end
|
20
|
+
|
21
|
+
it "should symbolize keys in child array's hashes" do
|
22
|
+
t = {"a" => [{"b" => "c", "d" => "e"}]}
|
23
|
+
te = {:a => [{:b => "c", :d => "e"}]}
|
24
|
+
ta = t.deep_symbolize_keys
|
25
|
+
te.should == ta
|
26
|
+
end
|
20
27
|
end
|
21
28
|
|
22
29
|
end
|