instance method
Hash#reject!
() -> ::Enumerator[[ K, V ], self?]
() { (K, V) -> ::boolish } -> self?
reject! {|key, value| ... } → self or nil
reject! → new_enumerator
hash.c
View on GitHub ↗
static VALUE
rb_hash_reject_bang(VALUE hash)
{
st_index_t n;
RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
rb_hash_modify(hash);
n = RHASH_SIZE(hash);
if (!n) return Qnil;
rb_hash_foreach(hash, delete_if_i, hash);
if (n == RHASH_SIZE(hash)) return Qnil;
return hash;
}
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.