Also remove Hash#slice!

This commit is contained in:
Douglas Eichelberger 2023-12-12 10:40:08 -08:00
parent 4a062b117c
commit 0ce84387fd
3 changed files with 1 additions and 31 deletions

1
.gitignore vendored
View File

@ -69,7 +69,6 @@
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_merge.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_merge.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_transform_values.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_transform_values.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/keys.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/keys.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/slice.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/duplicable.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/duplicable.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/exclude.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/exclude.rb

View File

@ -5,8 +5,6 @@ require "cli/parser"
require "utils/github" require "utils/github"
require "manpages" require "manpages"
require "active_support/core_ext/hash/slice"
module Homebrew module Homebrew
module_function module_function
@ -39,7 +37,7 @@ module Homebrew
sentences = {} sentences = {}
members.each do |group, hash| members.each do |group, hash|
hash.slice!(*public_members) hash.replace(hash.slice(*public_members))
hash.each { |login, name| hash[login] = "[#{name}](https://github.com/#{login})" } hash.each { |login, name| hash[login] = "[#{name}](https://github.com/#{login})" }
sentences[group] = hash.values.sort.to_sentence sentences[group] = hash.values.sort.to_sentence
end end

View File

@ -1,27 +0,0 @@
# frozen_string_literal: true
class Hash
# Replaces the hash with only the given keys.
# Returns a hash containing the removed key/value pairs.
#
# hash = { a: 1, b: 2, c: 3, d: 4 }
# hash.slice!(:a, :b) # => {:c=>3, :d=>4}
# hash # => {:a=>1, :b=>2}
def slice!(*keys)
omit = slice(*self.keys - keys)
hash = slice(*keys)
hash.default = default
hash.default_proc = default_proc if default_proc
replace(hash)
omit
end
# Removes and returns the key/value pairs matching the given keys.
#
# hash = { a: 1, b: 2, c: 3, d: 4 }
# hash.extract!(:a, :b) # => {:a=>1, :b=>2}
# hash # => {:c=>3, :d=>4}
def extract!(*keys)
keys.each_with_object(self.class.new) { |key, result| result[key] = delete(key) if has_key?(key) }
end
end