From e574904cb72805e773707e928442528d316e43a9 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 22 Jan 2024 10:41:48 -0800 Subject: [PATCH] Use each_with_object --- Library/Homebrew/extend/enumerable.rbi | 11 ----------- Library/Homebrew/formula_installer.rb | 13 ++++++------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Library/Homebrew/extend/enumerable.rbi b/Library/Homebrew/extend/enumerable.rbi index a95b0bf4bb4fa..207de60eb603d 100644 --- a/Library/Homebrew/extend/enumerable.rbi +++ b/Library/Homebrew/extend/enumerable.rbi @@ -1,16 +1,5 @@ # typed: strict -module Enumerable - requires_ancestor { Object } - - sig { - type_parameters(:key).params( - block: T.nilable(T.proc.params(o: Enumerable::Elem).returns(T.type_parameter(:key))), - ).returns(T::Hash[T.type_parameter(:key), Enumerable::Elem]) - } - def index_by(&block); end -end - class Hash sig { returns(T::Hash[Hash::K, Hash::V]) } def compact_blank; end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 292e91fc8cd6e..4d7a21cf960bd 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -565,8 +565,8 @@ def runtime_requirements(formula) def expand_requirements unsatisfied_reqs = Hash.new { |h, k| h[k] = [] } formulae = [formula] - formula_deps_map = {} - formula.recursive_dependencies.each { |dep| formula_deps_map[dep.name] = dep } + formula_deps_map = formula.recursive_dependencies + .each_with_object({}) { |dep, h| h[dep.name] = dep } while (f = formulae.pop) runtime_requirements = runtime_requirements(f) @@ -1206,11 +1206,10 @@ def previously_fetched_formula def fetch_bottle_tab @fetch_bottle_tab ||= begin formula.fetch_bottle_tab - @bottle_tab_runtime_dependencies = {} - formula.bottle_tab_attributes - .fetch("runtime_dependencies", []) - .each { |dep| @bottle_tab_runtime_dependencies[dep["full_name"]] = dep } - @bottle_tab_runtime_dependencies.freeze + @bottle_tab_runtime_dependencies = formula.bottle_tab_attributes + .fetch("runtime_dependencies", []) + .each_with_object({}) { |dep, h| h[dep["full_name"]] = dep } + .freeze true rescue DownloadError, ArgumentError @fetch_bottle_tab = true