Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/MrMurano/hash.rb
Overview
Class Method Summary collapse
-
.transform_keys_to_strings(value) ⇒ Object
take keys of hash and transform those to strings.
-
.transform_keys_to_symbols(value) ⇒ Object
take keys of hash and transform those to a symbols.
Class Method Details
.transform_keys_to_strings(value) ⇒ Object
take keys of hash and transform those to strings
12 13 14 15 16 17 |
# File 'lib/MrMurano/hash.rb', line 12 def self.transform_keys_to_strings(value) return value.map{|v| Hash.transform_keys_to_strings(v)} if value.is_a?(Array) return value if not value.is_a?(Hash) hash = value.inject({}){|memo,(k,v)| memo[k.to_s] = Hash.transform_keys_to_strings(v); memo} return hash end |
.transform_keys_to_symbols(value) ⇒ Object
take keys of hash and transform those to a symbols
5 6 7 8 9 10 |
# File 'lib/MrMurano/hash.rb', line 5 def self.transform_keys_to_symbols(value) return value.map{|v| Hash.transform_keys_to_symbols(v)} if value.is_a?(Array) return value if not value.is_a?(Hash) hash = value.inject({}){|memo,(k,v)| memo[k.to_sym] = Hash.transform_keys_to_symbols(v); memo} return hash end |