instance method
Hash#reject
() -> ::Enumerator[[ K, V ], ::Hash[K, V]]
() { (K, V) -> ::boolish } -> ::Hash[K, V]
reject {|key, value| ... } → new_hash
reject → new_enumerator
hash.c
View on GitHub ↗
static VALUE
rb_hash_reject(VALUE hash)
{
VALUE result;
RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
result = hash_dup_with_compare_by_id(hash);
if (!RHASH_EMPTY_P(hash)) {
rb_hash_foreach(result, delete_if_i, result);
compact_after_delete(result);
}
return result;
}
With a block given, returns a copy of self with zero or more entries removed; calls the block with each key-value pair; excludes the entry in the copy if the block returns a truthy value, includes it otherwise:
Example
h = {foo: 0, bar: 1, baz: 2} h.reject {|key, value| key.start_with?('b') } # => {foo: 0}
With no block given, returns a new Enumerator.
Related: see Methods for Deleting.