2007-12-21 08:48:59 +01:00
|
|
|
require 'set'
|
|
|
|
|
|
|
|
module ActiveSupport #:nodoc:
|
|
|
|
module CoreExtensions #:nodoc:
|
|
|
|
module Hash #:nodoc:
|
|
|
|
# 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))
|
|
|
|
module Except
|
|
|
|
# Returns a new hash without the given keys.
|
|
|
|
def except(*keys)
|
2008-10-27 07:47:01 +01:00
|
|
|
dup.except!(*keys)
|
2007-12-21 08:48:59 +01:00
|
|
|
end
|
|
|
|
|
2008-10-27 07:47:01 +01:00
|
|
|
# Replaces the hash without the given keys.
|
2007-12-21 08:48:59 +01:00
|
|
|
def except!(*keys)
|
2008-09-07 07:54:05 +02:00
|
|
|
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
|
|
|
|
keys.each { |key| delete(key) }
|
|
|
|
self
|
2007-12-21 08:48:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|