Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#stringify_keysObject

Turn all keys into string

Return a copy of the hash where all its keys are strings



8
9
10
# File 'lib/snibbets/hash.rb', line 8

def stringify_keys
  each_with_object({}) { |(k, v), hsh| hsh[k.to_s] = v.is_a?(Hash) ? v.stringify_keys : v }
end

#symbolize_keysObject

Turn all keys into symbols



13
14
15
# File 'lib/snibbets/hash.rb', line 13

def symbolize_keys
  each_with_object({}) { |(k, v), hsh| hsh[k.to_sym] = v.is_a?(Hash) ? v.symbolize_keys : v }
end