Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Hash#except

hsh.except(*keys) → a_hash

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

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