Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/kawaii/core_ext/hash.rb

Overview

Extend Hash.

Instance Method Summary (collapse)

Instance Method Details

- (Hash) symbolize_keys

Turns string keys to symbols.

Returns:

  • (Hash)

    a new hash



20
21
22
# File 'lib/kawaii/core_ext/hash.rb', line 20

def symbolize_keys
  update_keys(&:to_sym)
end

- (Hash) update_keys {|key| ... }

Transforms keys.

Yields:

  • (key)

    gives each key to the block

Yield Returns:

  • (key)

    new key

Returns:

  • (Hash)

    new hash with transformed keys



9
10
11
12
13
14
15
# File 'lib/kawaii/core_ext/hash.rb', line 9

def update_keys
  result = self.class.new
  each_key do |key|
    result[yield(key)] = self[key]
  end
  result
end