module Nanoc::Core::CoreExt::HashExtensions
Public Instance Methods
__nanoc_freeze_recursively()
click to toggle source
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 Array#__nanoc_freeze_recursively
@return [void]
# File lib/nanoc/core/core_ext/hash.rb, line 39 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_recursively()
click to toggle source
# File lib/nanoc/core/core_ext/hash.rb, line 22 def __nanoc_stringify_keys_recursively hash = {} each_pair do |key, value| new_key = key.is_a?(Symbol) ? key.to_s : key new_value = value.respond_to?(:__nanoc_stringify_keys_recursively) ? value.__nanoc_stringify_keys_recursively : value hash[new_key] = new_value end hash end
__nanoc_symbolize_keys_recursively()
click to toggle source
Returns a new hash where all keys are recursively converted to symbols by calling {Nanoc::ArrayExtensions#__nanoc_symbolize_keys_recursively} or {Nanoc::HashExtensions#__nanoc_symbolize_keys_recursively}.
@return [Hash] The converted hash
# 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 = value.respond_to?(:__nanoc_symbolize_keys_recursively) ? value.__nanoc_symbolize_keys_recursively : value hash[new_key] = new_value end hash end