Sha256: 7484cf4ca3ba870c0948ab27de2e706c061b908dbacb48a8126301bdae2b3a2b

Contents?: true

Size: 780 Bytes

Versions: 34

Compression:

Stored size: 780 Bytes

Contents

# frozen_string_literal: true

class Hash
  # Returns a hash that includes everything except given keys.
  #   hash = { a: true, b: false, c: nil }
  #   hash.except(:c)     # => { a: true, b: false }
  #   hash.except(:a, :b) # => { c: nil }
  #   hash                # => { a: true, b: false, c: nil }
  #
  # This is useful for limiting a set of parameters to everything but a few known toggles:
  #   @person.update(params[:person].except(:admin))
  def except(*keys)
    slice(*self.keys - keys)
  end

  # Removes the given keys from hash and returns it.
  #   hash = { a: true, b: false, c: nil }
  #   hash.except!(:c) # => { a: true, b: false }
  #   hash             # => { a: true, b: false }
  def except!(*keys)
    keys.each { |key| delete(key) }
    self
  end
end

Version data entries

34 entries across 32 versions & 7 rubygems

Version Path
activesupport-6.0.3.7 lib/active_support/core_ext/hash/except.rb
activesupport-6.0.3.6 lib/active_support/core_ext/hash/except.rb
activesupport-6.0.3.5 lib/active_support/core_ext/hash/except.rb
activesupport-6.0.3.4 lib/active_support/core_ext/hash/except.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/core_ext/hash/except.rb
activesupport-6.0.3.3 lib/active_support/core_ext/hash/except.rb
simple_ext-0.1.3 lib/simple_ext/hash/except.rb
activesupport-6.0.3.2 lib/active_support/core_ext/hash/except.rb
activesupport-6.0.3.1 lib/active_support/core_ext/hash/except.rb
activesupport-6.0.3 lib/active_support/core_ext/hash/except.rb
activesupport-6.0.3.rc1 lib/active_support/core_ext/hash/except.rb
activesupport-6.0.2.2 lib/active_support/core_ext/hash/except.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/core_ext/hash/except.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/core_ext/hash/except.rb
simple_ext-0.1.2 lib/simple_ext/hash/except.rb
activesupport-6.0.2.1 lib/active_support/core_ext/hash/except.rb
activesupport-6.0.2 lib/active_support/core_ext/hash/except.rb
activesupport-6.0.2.rc2 lib/active_support/core_ext/hash/except.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/activesupport-6.0.1/lib/active_support/core_ext/hash/except.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/core_ext/hash/except.rb