Add documentation to HashWithIndifferentAccess#except

https://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html#method-i-except
Currently HashWithIndifferentAccess#except has no documentation.
Since it's behavior is different from Hash#except, so it deserves
its own documentation.
This commit is contained in:
OKURA Masafumi 2021-03-20 23:37:13 +09:00 committed by GitHub
parent a8a1afd455
commit 8a56380c53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -295,6 +295,10 @@ module ActiveSupport
super(convert_key(key))
end
# Returns a hash with indifferent access that includes everything except given keys.
# hash = { a: "x", b: "y", c: 10 }.with_indifferent_access
# hash.except(:a, "b") # => {c: 10}.with_indifferent_access
# hash # => { a: "x", b: "y", c: 10 }.with_indifferent_access
def except(*keys)
slice(*self.keys - keys.map { |key| convert_key(key) })
end