Module: Gorillib::Hashlike::OverrideEnumerable
- Defined in:
- lib/gorillib/hashlike.rb
Overview
Overrides the implementation in Enumerable, which iterates on keys, not key/value pairs
Instance Method Summary collapse
-
#reject(&block) ⇒ Object
Deletes every key-value pair from +hsh+ for which +block+ evaluates to true (similar to Hashlike#delete_if), but works on (and returns) a copy of the +hsh+.
-
#select(&block) ⇒ Object
Deletes every key-value pair from +hsh+ for which +block+ evaluates to false (similar to Hashlike#keep_if), but works on (and returns) a copy of the +hsh+.
Instance Method Details
#hsh.reject ⇒ Hashlike #hsh.reject(->an_enumerator) ⇒ Enumerator
Deletes every key-value pair from +hsh+ for which +block+ evaluates to true (similar to Hashlike#delete_if), but works on (and returns) a copy of the +hsh+. Equivalent to hsh.dup.delete_if.
Overrides the implementation in Enumerable, which does the keys wrong.
686 687 688 689 |
# File 'lib/gorillib/hashlike.rb', line 686 def reject(&block) return enum_for(:reject) unless block_given? self.dup.delete_if(&block) end |
#hsh.select ⇒ Hashlike #hsh.select(->an_enumerator) ⇒ Enumerator
Deletes every key-value pair from +hsh+ for which +block+ evaluates to false (similar to Hashlike#keep_if), but works on (and returns) a copy of the +hsh+. Equivalent to hsh.dup.keep_if.
Overrides the implementation in Enumerable, which does the keys wrong.
715 716 717 718 |
# File 'lib/gorillib/hashlike.rb', line 715 def select(&block) return enum_for(:select) unless block_given? self.dup.keep_if(&block) end |