Module: Dr::Utils
- Defined in:
- lib/dr/utils.rb
Class Method Summary collapse
Class Method Details
.stringify_keys(hash) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/dr/utils.rb', line 17 def self.stringify_keys(hash) return hash unless hash.is_a? Hash hash.inject({}) do |new_hash, (key, value)| new_hash[key.to_s] = stringify_keys value new_hash end end |
.stringify_symbols(var) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dr/utils.rb', line 26 def self.stringify_symbols(var) case when var.is_a?(Hash) var.inject({}) do |new_hash, (key, value)| new_hash[key.to_s] = stringify_keys value new_hash end when var.is_a?(Array) var.map {|e| stringify_symbols e} when var.is_a?(Symbol) var.to_s else var end end |
.symbolise_keys(hash) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/dr/utils.rb', line 6 def self.symbolise_keys(hash) if hash.is_a? Hash hash.inject({}) do |new_hash, (key, value)| new_hash[key.to_sym] = symbolise_keys value new_hash end else hash end end |