Module: Nanoc::HashExtensions Private

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

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#__nanoc_freeze_recursivelyvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Freezes the contents of the hash, as well as all hash values. The hash values will be frozen using #__nanoc_freeze_recursively if they respond to that message, or #freeze if they do not.

See Also:

  • Array#__nanoc_freeze_recursively

Since:

  • 3.2.0



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/nanoc/base/core_ext/hash.rb', line 27

def __nanoc_freeze_recursively
  return if frozen?
  freeze
  each_pair do |_key, value|
    if value.respond_to?(:__nanoc_freeze_recursively)
      value.__nanoc_freeze_recursively
    else
      value.freeze
    end
  end
end

#__nanoc_symbolize_keys_recursivelyHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new hash where all keys are recursively converted to symbols by calling ArrayExtensions#__nanoc_symbolize_keys_recursively or #__nanoc_symbolize_keys_recursively.

Returns:

  • (Hash)

    The converted hash



8
9
10
11
12
13
14
15
16
# File 'lib/nanoc/base/core_ext/hash.rb', line 8

def __nanoc_symbolize_keys_recursively
  hash = {}
  each_pair do |key, value|
    new_key   = key.respond_to?(:to_sym) ? key.to_sym : key
    new_value = value.respond_to?(:__nanoc_symbolize_keys_recursively) ? value.__nanoc_symbolize_keys_recursively : value
    hash[new_key] = new_value
  end
  hash
end