Method: Set#keep_if
- Defined in:
- lib/set.rb
#keep_if(&block) ⇒ Object
Deletes every element of the set for which block evaluates to false, and returns self. Returns an enumerator if no block is given.
557 558 559 560 561 562 563 |
# File 'lib/set.rb', line 557 def keep_if(&block) block_given? or return enum_for(__method__) { size } # Instead of directly using @hash.keep_if, perform enumeration # using self.each that subclasses may override. reject(&block).each { |o| @hash.delete(o) } self end |