Skip to content
instance method

Array#filter!

() { (Elem item) -> ::boolish } -> self?
() -> ::Enumerator[Elem, self?]
filter! {|element| ... } → self or nil
filter! → new_enumerator

Alias of #select!

With a block given, calls the block with each element of self; removes from self those elements for which the block returns false or nil.

Returns self if any elements were removed:

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

Returns nil if no elements were removed.

With no block given, returns a new Enumerator.

Related: see Methods for Deleting.

See also #select! #filter #find #fill also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0