Module: Nanoc3::HashExtensions

Included in:
Hash
Defined in:
lib/nanoc3/base/core_ext/hash.rb

Instance Method Summary (collapse)

Instance Method Details

- (Hash) stringify_keys

Returns a new hash where all keys are recursively converted to strings by calling ArrayExtensions#stringify<em>keys or #stringify</em>keys.

Returns:

  • (Hash)

    The converted hash



21
22
23
24
25
# File 'lib/nanoc3/base/core_ext/hash.rb', line 21

def stringify_keys
  inject({}) do |hash, (key, value)|
    hash.merge(key.to_s => value.respond_to?(:stringify_keys) ? value.stringify_keys : value)
  end
end

- (Hash) symbolize_keys

Returns a new hash where all keys are recursively converted to symbols by calling ArrayExtensions#symbolize<em>keys or #symbolize</em>keys.

Returns:

  • (Hash)

    The converted hash



10
11
12
13
14
# File 'lib/nanoc3/base/core_ext/hash.rb', line 10

def symbolize_keys
  inject({}) do |hash, (key, value)|
    hash.merge(key.to_sym => value.respond_to?(:symbolize_keys) ? value.symbolize_keys : value)
  end
end