Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/MrMurano/hash.rb

Overview

Class Method Summary collapse

Class Method Details

.transform_keys_to_strings(value) ⇒ Object

take keys of hash and transform those to strings



11
12
13
14
15
# File 'lib/MrMurano/hash.rb', line 11

def self.transform_keys_to_strings(value)
  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
# File 'lib/MrMurano/hash.rb', line 5

def self.transform_keys_to_symbols(value)
  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