Class: SimpleGeo::HashUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_geo/hash_utils.rb

Class Method Summary collapse

Class Method Details

.recursively_symbolize_keys(object) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/simple_geo/hash_utils.rb', line 10

def self.recursively_symbolize_keys(object)
  if object.is_a? Hash
    symbolized_hash = symbolize_keys(object)
    symbolized_hash.each do |key, value|
      symbolized_hash[key] = recursively_symbolize_keys(value)
    end
    symbolized_hash
  elsif object.is_a? Array
    object.map { |value| recursively_symbolize_keys(value) }
  else
    object
  end
end

.symbolize_keys(hash) ⇒ Object



3
4
5
6
7
8
# File 'lib/simple_geo/hash_utils.rb', line 3

def self.symbolize_keys(hash)
  hash.inject({}) do |options, (key, value)|
    options[(key.to_sym rescue key) || key] = value
    options
  end
end