class Lumberjack::Tags
def expand_runtime_values(hash)
-
(Hash)
- The hash with string keys and expanded values.
Parameters:
-
hash
(Hash
) -- The hash to transform.
def expand_runtime_values(hash) return nil if hash.nil? if hash.all? { |key, value| key.is_a?(String) && !value.is_a?(Proc) } return hash end copy = {} hash.each do |key, value| if value.is_a?(Proc) && (value.arity == 0 || value.arity == -1) value = value.call end copy[key.to_s] = value end copy end
def stringify_keys(hash)
-
(Hash)
- The hash with string keys.
Parameters:
-
hash
(Hash
) -- The hash to transform.
def stringify_keys(hash) return nil if hash.nil? if hash.keys.all? { |key| key.is_a?(String) } hash elsif hash.respond_to?(:transform_keys) hash.transform_keys(&:to_s) else copy = {} hash.each do |key, value| copy[key.to_s] = value end copy end end