Remove monkey-patched Hash#except
This commit is contained in:
parent
e8d87fe256
commit
7ebee52614
@ -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"
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user