Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Set#keep_if
() { (A) -> untyped } -> self
keep_if(&block)
lib/set.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/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
Deletes every element of the set for which block evaluates to false, and returns self. Returns an enumerator if no block is given.