Module: Nanoc::HashExtensions
- Included in:
- Hash
- Defined in:
- lib/nanoc/base/core_ext/hash.rb
Instance Method Summary (collapse)
-
- (String) checksum
private
Calculates the checksum for this hash.
-
- (void) freeze_recursively
Freezes the contents of the hash, as well as all hash values.
-
- (Object) stringify_keys
deprecated
Deprecated.
Renamed to #stringify_keys_recursively
-
- (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.
-
- (Object) symbolize_keys
deprecated
Deprecated.
Renamed to #symbolize_keys_recursively
-
- (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.
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.
68 69 70 |
# File 'lib/nanoc/base/core_ext/hash.rb', line 68 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.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/nanoc/base/core_ext/hash.rb', line 50 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
Renamed to #stringify_keys_recursively
37 38 39 |
# File 'lib/nanoc/base/core_ext/hash.rb', line 37 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.
30 31 32 33 34 |
# File 'lib/nanoc/base/core_ext/hash.rb', line 30 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
Renamed to #symbolize_keys_recursively
21 22 23 |
# File 'lib/nanoc/base/core_ext/hash.rb', line 21 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.
10 11 12 13 14 15 16 17 18 |
# File 'lib/nanoc/base/core_ext/hash.rb', line 10 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 |