class Hash

From: github.com/rails/rails/blob/001b270611cd9cb653124775899bdbc2548333ab/activesupport/lib/active_support/core_ext/hash/except.rb

Public Instance Methods

except(*keys) click to toggle source

Returns a hash that includes everything but the given keys.

hash = { a: true, b: false, c: nil}
hash.except(:c) # => { a: true, b: false}
hash # => { a: true, b: false, c: nil}

This is useful for limiting a set of parameters to everything but a few known toggles:

@person.update(params[:person].except(:admin))
# File lib/openstudio/core_ext/hash.rb, line 45
def except(*keys)
  dup.except!(*keys)
end
except!(*keys) click to toggle source

Replaces the hash without the given keys.

hash = { a: true, b: false, c: nil}
hash.except!(:c) # => { a: true, b: false}
hash # => { a: true, b: false }
# File lib/openstudio/core_ext/hash.rb, line 53
def except!(*keys)
  keys.each { |key| delete(key) }
  self
end