From 059ab7fac64635fd36537dbc41473cd46ee4cf50 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 9 Feb 2024 17:55:25 +0100 Subject: [PATCH] Avoid `T.cast`. --- Library/Homebrew/cask/cask_loader.rb | 5 +---- Library/Homebrew/formulary.rb | 8 ++------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cask/cask_loader.rb b/Library/Homebrew/cask/cask_loader.rb index cf2ac67abb0241..c4629e8ae446f0 100644 --- a/Library/Homebrew/cask/cask_loader.rb +++ b/Library/Homebrew/cask/cask_loader.rb @@ -232,10 +232,7 @@ class FromDefaultTapLoader < FromTapLoader } def self.try_new(ref, warn: false) ref = ref.to_s - - return unless (match = ref.match(HOMEBREW_DEFAULT_TAP_CASK_REGEX)) - - token = match[:token] + return unless (token = ref[HOMEBREW_DEFAULT_TAP_CASK_REGEX, :token]) ref = "#{CoreCaskTap.instance}/#{token}" diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 581192362c2cba..c9ebae97130635 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -694,9 +694,7 @@ class FromTapLoader < FormulaLoader } def self.try_new(ref, from: T.unsafe(nil), warn: false) ref = ref.to_s - return unless (match = ref.match(HOMEBREW_TAP_FORMULA_REGEX)) - - alias_name = T.cast(match[:name], String) + return unless (name = alias_name = ref[HOMEBREW_TAP_FORMULA_REGEX, :name]) name, tap, type = Formulary.tap_formula_name_type(ref, warn: warn) path = Formulary.find_formula_in_tap(name, tap) @@ -853,10 +851,8 @@ class FromAPILoader < FormulaLoader def self.try_new(ref, from: T.unsafe(nil), warn: false) return if Homebrew::EnvConfig.no_install_from_api? return unless ref.is_a?(String) + return unless (name = alias_name = ref[HOMEBREW_DEFAULT_TAP_FORMULA_REGEX, :name]) - return unless (match = ref.match(HOMEBREW_DEFAULT_TAP_FORMULA_REGEX)) - - name = alias_name = T.cast(match[:name], String) if !Homebrew::API::Formula.all_formulae.key?(name) && !Homebrew::API::Formula.all_aliases.key?(name) && !Homebrew::API::Formula.all_renames.key?(name)