Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/core_ext/hash.rb
Instance Method Summary collapse
- #map_keys(&blk) ⇒ Object
- #map_keys_with_values(&blk) ⇒ Object
- #map_values(&blk) ⇒ Object
- #map_values_with_keys(&blk) ⇒ Object
Instance Method Details
#map_keys(&blk) ⇒ Object
2 3 4 |
# File 'lib/core_ext/hash.rb', line 2 def map_keys &blk map_keys_with_values { |k, v| blk.call(k) } end |
#map_keys_with_values(&blk) ⇒ Object
6 7 8 9 10 |
# File 'lib/core_ext/hash.rb', line 6 def map_keys_with_values &blk result = {} each { |k, v| result[blk.call(k, v)] = v } result end |
#map_values(&blk) ⇒ Object
12 13 14 |
# File 'lib/core_ext/hash.rb', line 12 def map_values &blk map_values_with_keys { |k, v| blk.call(v) } end |
#map_values_with_keys(&blk) ⇒ Object
16 17 18 19 20 |
# File 'lib/core_ext/hash.rb', line 16 def map_values_with_keys &blk result = {} each { |k, v| result[k] = blk.call(k, v) } result end |