Class: RestfulPress::HashUtils

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

Class Method Summary collapse

Class Method Details

.recursively_symbolize_keys(object) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/restful_press/hash_utils.rb', line 12

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



5
6
7
8
9
10
# File 'lib/restful_press/hash_utils.rb', line 5

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