Module: Nanoc::Core::CoreExt::HashExtensions

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

Instance Method Summary collapse

Instance Method Details

#__nanoc_freeze_recursivelyvoid

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


49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/nanoc/core/core_ext/hash.rb', line 49

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_stringify_keys_recursivelyObject



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

def __nanoc_stringify_keys_recursively
  hash = {}
  each_pair do |key, value|
    new_key   = key.is_a?(Symbol) ? key.to_s : key
    new_value =
      if value.respond_to?(:__nanoc_stringify_keys_recursively)
        value.__nanoc_stringify_keys_recursively
      else
        value
      end
    hash[new_key] = new_value
  end
  hash
end

#__nanoc_symbolize_keys_recursivelyHash

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

Returns:

  • (Hash)

    The converted hash



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nanoc/core/core_ext/hash.rb', line 12

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