Sha256: 43350d6f0acadb5cf30f24be42eea39e438dfd5728447257e7963fa1bdce25f4

Contents?: true

Size: 743 Bytes

Versions: 92

Compression:

Stored size: 743 Bytes

Contents

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)
    dup.except!(*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

92 entries across 89 versions & 11 rubygems

Version Path
cmis-ruby-0.5.38 lib/ext/hash/except.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/core_ext/hash/except.rb
cmis-ruby-0.5.37 lib/ext/hash/except.rb
activesupport-5.1.7 lib/active_support/core_ext/hash/except.rb
activesupport-5.1.7.rc1 lib/active_support/core_ext/hash/except.rb
activesupport-5.1.6.2 lib/active_support/core_ext/hash/except.rb
activesupport-5.0.7.2 lib/active_support/core_ext/hash/except.rb
activesupport-5.1.6.1 lib/active_support/core_ext/hash/except.rb
activesupport-5.0.7.1 lib/active_support/core_ext/hash/except.rb
activesupport-5.1.6 lib/active_support/core_ext/hash/except.rb
activesupport-5.0.7 lib/active_support/core_ext/hash/except.rb
tdiary-5.0.8 vendor/bundle/gems/activesupport-5.1.5/lib/active_support/core_ext/hash/except.rb
activesupport-5.1.5 lib/active_support/core_ext/hash/except.rb
activesupport-5.1.5.rc1 lib/active_support/core_ext/hash/except.rb
pract6-0.1.0 .gem/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/core_ext/hash/except.rb
cmis-ruby-0.5.36 lib/ext/hash/except.rb
activesupport-5.1.4 lib/active_support/core_ext/hash/except.rb
activesupport-5.0.6 lib/active_support/core_ext/hash/except.rb
activesupport-5.1.4.rc1 lib/active_support/core_ext/hash/except.rb
activesupport-5.0.6.rc1 lib/active_support/core_ext/hash/except.rb