Module: Prmd::HashHelpers Private
- Defined in:
- lib/prmd/hash_helpers.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Hash helper methods
Class Method Summary collapse
-
.deep_symbolize_keys(hash) ⇒ Hash
private
Attempts to convert all keys in the hash to a Symbol.
-
.deep_transform_keys(hash) {|Object| ... } ⇒ Hash
private
Think of this as hash.keys.map! { |key| }, that actually maps recursively.
Class Method Details
.deep_symbolize_keys(hash) ⇒ Hash
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.
Attempts to convert all keys in the hash to a Symbol. This operation is recursive with subhashes
12 13 14 15 16 17 18 19 20 |
# File 'lib/prmd/hash_helpers.rb', line 12 def self.deep_symbolize_keys(hash) deep_transform_keys(hash) do |key| if key.respond_to?(:to_sym) key.to_sym else key end end end |
.deep_transform_keys(hash) {|Object| ... } ⇒ Hash
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.
Think of this as hash.keys.map! { |key| }, that actually maps recursively.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/prmd/hash_helpers.rb', line 27 def self.deep_transform_keys(hash, &block) result = {} hash.each do |key, value| new_key = yield(key) new_value = value new_value = deep_transform_keys(value, &block) if value.is_a?(Hash) result[new_key] = new_value end result end |