Module: Hash::MapToHash
- Defined in:
- lib/core_ext/hash/map_to_hash.rb
Instance Method Summary collapse
-
#map_to_hash(options = {}, &block) ⇒ Object
Update all values in a hash.
Instance Method Details
#map_to_hash(options = {}, &block) ⇒ Object
Update all values in a hash. Passes key,value pairs to its block, replaces the pair with the block’s return value.
6 7 8 9 10 11 12 13 14 |
# File 'lib/core_ext/hash/map_to_hash.rb', line 6 def map_to_hash( = {}, &block) Hash.new.tap do |result| self.each_pair do |key,value| value = _deep_convert(value, block) if [:deep] new_key, new_value = block.call(key, value) result[new_key] = new_value end end end |