Module: Nanoc::HashExtensions

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

Instance Method Summary (collapse)

Instance Method Details

- (String) checksum

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.

Calculates the checksum for this hash. Any change to this hash will result in a different checksum.

Returns:

  • (String)

    The checksum for this hash



67
68
69
# File 'lib/nanoc/base/core_ext/hash.rb', line 67

def checksum
  Nanoc::Checksummer.calc(self)
end

- (void) freeze_recursively

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 #freeze_recursively if they respond to that message, or #freeze if they do not.

See Also:

  • Array#freeze_recursively

Since:

  • 3.2.0



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

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

- (Object) stringify_keys

Deprecated.


36
37
38
# File 'lib/nanoc/base/core_ext/hash.rb', line 36

def stringify_keys
  stringify_keys_recursively
end

- (Hash) stringify_keys_recursively

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

Returns:

  • (Hash)

    The converted hash



29
30
31
32
33
# File 'lib/nanoc/base/core_ext/hash.rb', line 29

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

- (Object) symbolize_keys

Deprecated.


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

def symbolize_keys
  symbolize_keys_recursively
end

- (Hash) symbolize_keys_recursively

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

Returns:

  • (Hash)

    The converted hash



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

def 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?(:symbolize_keys_recursively) ? value.symbolize_keys_recursively : value
    hash[new_key] = new_value
  end
  hash
end