Remove monkey-patched Hash#except

This commit is contained in:
Douglas Eichelberger 2023-12-12 10:12:01 -08:00
parent e8d87fe256
commit 7ebee52614
2 changed files with 0 additions and 25 deletions

View File

@ -16,7 +16,6 @@ require "active_support/core_ext/array/access"
require "active_support/core_ext/enumerable"
require "active_support/core_ext/file/atomic"
require "active_support/core_ext/hash/deep_merge"
require "active_support/core_ext/hash/except"
require "active_support/core_ext/hash/keys"
require "active_support/core_ext/string/exclude"
require "active_support/core_ext/string/filters"

View File

@ -1,24 +0,0 @@
# 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 unless method_defined?(:except)
# 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