Skip to content
instance method

Hash#reject!

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

With a block given, calls the block with each entry’s key and value; removes the entry from self if the block returns a truthy value.

Return self if any entries were removed, nil otherwise:

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

With no block given, returns a new Enumerator.

Related: see Methods for Deleting.

See also #reject #replace #rehash #select also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0