Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/hash.rb
Instance Method Summary collapse
Instance Method Details
#each_with_filter(*filter, &block) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/hash.rb', line 2 def each_with_filter(*filter, &block) filter.each do |key| if key.is_a?(Array) values = key.map do |k| self.fetch(k) if has_key?(k) end values.compact! block.call(key, values.join(" ")) else with(key, &block) end end end |
#with(key) {|key, fetch(key)| ... } ⇒ Object
16 17 18 |
# File 'lib/hash.rb', line 16 def with(key) yield(key, fetch(key)) if has_key?(key) end |