Skip to content
instance method

Array#keep_if

() { (Elem item) -> ::boolish } -> self
() -> ::Enumerator[Elem, self]
keep_if {|element| ... } → self
keep_if → new_enumerator

With a block given, calls the block with each element of self; removes the element from self if the block does not return a truthy value:

Example
a = [:foo, 'bar', 2, :bam]
a.keep_if {|element| element.to_s.start_with?('b') } # => ["bar", :bam]

With no block given, returns a new Enumerator.

Related: see Methods for Deleting.

See also #join #last #intersection #length also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0