File: active_support/core_ext/hash/except.rb

Overview
Module Structure
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: ActiveSupport#3
  module: CoreExtensions#4
  module: Hash#5
  module: Except#10
has properties
method: except / 1 #12
method: except! / 1 #17

Code

   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