Sha256: 3ad27bad383004625574334e3ecea30878a1fd2e162ece2034a9ea5964b6aa20

Contents?: true

Size: 793 Bytes

Versions: 11

Compression:

Stored size: 793 Bytes

Contents

class Hash
  # 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))
  #
  # If the receiver responds to +convert_key+, the method is called on each of the
  # arguments. This allows +except+ to play nice with hashes with indifferent access
  # for instance:
  #
  #   {:a => 1}.with_indifferent_access.except(:a)  # => {}
  #   {:a => 1}.with_indifferent_access.except("a") # => {}
  #
  def except(*keys)
    dup.except!(*keys)
  end

  # Replaces the hash without the given keys.
  def except!(*keys)
    keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
    keys.each { |key| delete(key) }
    self
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
csd-0.1.5 lib/active_support/core_ext/hash/except.rb
csd-0.1.4 lib/active_support/core_ext/hash/except.rb
csd-0.1.3 lib/active_support/core_ext/hash/except.rb
csd-0.1.2 lib/active_support/core_ext/hash/except.rb
csd-0.1.1 lib/active_support/core_ext/hash/except.rb
csd-0.1.0 lib/active_support/core_ext/hash/except.rb
csd-0.0.16 lib/active_support/core_ext/hash/except.rb
activesupport-3.0.0.beta4 lib/active_support/core_ext/hash/except.rb
activesupport-3.0.0.beta3 lib/active_support/core_ext/hash/except.rb
activesupport-3.0.0.beta2 lib/active_support/core_ext/hash/except.rb
activesupport-3.0.0.beta lib/active_support/core_ext/hash/except.rb