lib/chargify2/utils.rb in chargify2-0.2.5 vs lib/chargify2/utils.rb in chargify2-0.2.6
- old
+ new
@@ -1,16 +1,20 @@
module Chargify2
module Utils
module HashExtensions
- # Symbolizes keys for flat or nested hashes (operates recursively on nested hashes)
- def symbolize_keys
- Hash[
- self.map { |key, value|
- k = key.to_sym
- v = value.is_a?(Hash) ? value.symbolize_keys : value
- [k,v]
- }
- ]
+ def recursive_symbolize_keys
+ self.inject({}){|result, (key, value)|
+ new_key = case key
+ when String then key.to_sym
+ else key
+ end
+ new_value = case value
+ when Hash then value.recursive_symbolize_keys
+ else value
+ end
+ result[new_key] = new_value
+ result
+ }
end
end
end
-end
\ No newline at end of file
+end