Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#symbolize_keysHash

Converts the keys of the hash to symbols.

Examples:

{ 'one' => 1, 'two' => 2 }.symbolize_keys #=> { :one => 1, :two => 2 }
{ 1 => "a" }.symbolize_keys #=> { 1 => "a" }


10
11
12
# File 'lib/powerpack/hash/symbolize_keys.rb', line 10

def symbolize_keys
  Hash[map { |(k, v)| [(k.to_sym rescue k), v] }]
end