Module: Incognia::Util

Defined in:
lib/incognia_api/util.rb

Class Method Summary collapse

Class Method Details

.symbolize_names(object) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/incognia_api/util.rb', line 3

def self.symbolize_names(object)
  case object
  when Hash
    new_hash = {}
    object.each do |key, value|
      key = (begin key.to_sym; rescue StandardError; key end) || key
      new_hash[key] = symbolize_names(value)
    end
    new_hash
  when Array
    object.map { |value| symbolize_names(value) }
  else
    object
  end
end