Module: ActiveSupport::CoreExtensions::Hash::Except

Included in:
Hash
Defined in:
lib/active_support/core_ext/hash/except.rb

Overview

Return a hash that includes everything but the given keys. This is useful for limiting a set of parameters to everything but a few known toggles:

@person.update_attributes(params[:person].except(:admin))

Instance Method Summary collapse

Instance Method Details

#except(*keys) ⇒ Object

Returns a new hash without the given keys.



12
13
14
15
# File 'lib/active_support/core_ext/hash/except.rb', line 12

def except(*keys)
  rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
  reject { |key,| rejected.include?(key) }
end

#except!(*keys) ⇒ Object

Replaces the hash without only the given keys.



18
19
20
# File 'lib/active_support/core_ext/hash/except.rb', line 18

def except!(*keys)
  replace(except(*keys))
end