End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Hash#except
hsh.except(*keys) → a_hash
hash.c
View on GitHub ↗
static VALUE
rb_hash_except(int argc, VALUE *argv, VALUE hash)
{
int i;
VALUE key, result;
result = hash_dup_with_compare_by_id(hash);
for (i = 0; i < argc; i++) {
key = argv[i];
rb_hash_delete(result, key);
}
return result;
}
Returns a new Hash excluding entries for the given keys:
Example
h = { a: 100, b: 200, c: 300 } h.except(:a) #=> {:b=>200, :c=>300}
Any given keys that are not found are ignored.
Ruby version changes
-
3.0
-
Hash#excepthas been added, which returns a hash excluding the given keys and their values. [Feature #15822]
-