Skip to content
instance method

Hash#filter!

() { (K, V) -> ::boolish } -> self?
() -> ::Enumerator[[ K, V ], self?]
filter!

Alias of #select!

With a block given, calls the block with each entry’s key and value; removes from self each entry for which the block returns false or nil.

Returns self if any entries were removed, nil otherwise:

Example
h = {foo: 0, bar: 1, baz: 2}
h.select! {|key, value| value < 2 } # => {foo: 0, bar: 1}
h.select! {|key, value| value < 2 } # => nil

With no block given, returns a new Enumerator.

Related: see Methods for Deleting.

See also #select! #filter #flatten #fetch_values also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0