Skip to content
instance method

Hash#except

(*K) -> ::Hash[K, V]
except(*keys) → new_hash

Returns a copy of self that excludes entries for the given keys; any keys that are not found are ignored:

Example
h = {foo:0, bar: 1, baz: 2} # => {:foo=>0, :bar=>1, :baz=>2}
h.except(:baz, :foo)        # => {:bar=>1}
h.except(:bar, :nosuch)     # => {:foo=>0, :baz=>2}

Related: see Methods for Deleting.

Ruby version changes

  1. 3.0
See also #eql? #fetch #empty? #fetch_values also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0