~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activesupport/lib/active_support/core_ext/hash/except.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'set'
2
 
 
3
 
module ActiveSupport #:nodoc:
4
 
  module CoreExtensions #:nodoc:
5
 
    module Hash #:nodoc:
6
 
      # Return a hash that includes everything but the given keys. This is useful for
7
 
      # limiting a set of parameters to everything but a few known toggles:
8
 
      #
9
 
      #   @person.update_attributes(params[:person].except(:admin))
10
 
      module Except
11
 
        # Returns a new hash without the given keys.
12
 
        def except(*keys)
13
 
          dup.except!(*keys)
14
 
        end
15
 
 
16
 
        # Replaces the hash without the given keys.
17
 
        def except!(*keys)
18
 
          keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
19
 
          keys.each { |key| delete(key) }
20
 
          self
21
 
        end
22
 
      end
23
 
    end
24
 
  end
25
 
end