Module: Enumerable

Defined in:
lib/little_sms/enumerable.rb

Overview

Convert all keys to symbols

Instance Method Summary collapse

Instance Method Details

#symbolize_keysObject



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

def symbolize_keys
  symbolize = lambda { |v| v.respond_to?(:map) ? v.symbolize_keys : v }
  case self
  when Hash
    Hash[ self.map { |key, value|
      k = key.kind_of?(String) ? key.to_sym : key
      v = symbolize.call(value)
      [k, v]
    }]
  when Array
    self.map { |value| symbolize.call(value) }
  else
    self
  end
end