Skip to content
instance method

Hash#select!

() { (K, V) -> ::boolish } -> self?
() -> ::Enumerator[[ K, V ], self?]
select! {|key, value| ... } → self or nil
select! → new_enumerator

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 #shift #replace #size also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0