diff --git a/.gitignore b/.gitignore index 806bde19fc..21b10a5f1e 100644 --- a/.gitignore +++ b/.gitignore @@ -73,7 +73,6 @@ !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/blank.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/try.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/filters.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/indent.rb diff --git a/Library/Homebrew/cask/artifact/artifact.rb b/Library/Homebrew/cask/artifact/artifact.rb index 4ab625dfdf..c1d2f306b0 100644 --- a/Library/Homebrew/cask/artifact/artifact.rb +++ b/Library/Homebrew/cask/artifact/artifact.rb @@ -20,7 +20,7 @@ module Cask raise CaskInvalidError.new(cask.token, "No source provided for #{english_name}.") if source.blank? - unless options.try(:key?, :target) + unless options&.key?(:target) raise CaskInvalidError.new(cask.token, "#{english_name} '#{source}' requires a target.") end diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 2bee5d03aa..a9e42cc6b3 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -300,12 +300,12 @@ on_request: true) def missing_cask_and_formula_dependencies cask_and_formula_dependencies.reject do |cask_or_formula| - installed = if cask_or_formula.respond_to?(:any_version_installed?) - cask_or_formula.any_version_installed? - else - cask_or_formula.try(:installed?) + case cask_or_formula + when Formula + cask_or_formula.any_version_installed? && cask_or_formula.optlinked? + when Cask + cask_or_formula.installed? end - installed && (cask_or_formula.respond_to?(:optlinked?) ? cask_or_formula.optlinked? : true) end end diff --git a/Library/Homebrew/dev-cmd/bump.rb b/Library/Homebrew/dev-cmd/bump.rb index 736f163441..5566675408 100644 --- a/Library/Homebrew/dev-cmd/bump.rb +++ b/Library/Homebrew/dev-cmd/bump.rb @@ -279,7 +279,7 @@ module Homebrew def retrieve_pull_requests(formula_or_cask, name, state:, version: nil) tap_remote_repo = formula_or_cask.tap&.remote_repo || formula_or_cask.tap&.full_name pull_requests = GitHub.fetch_pull_requests(name, tap_remote_repo, state: state, version: version) - if pull_requests.try(:any?) + if pull_requests&.any? pull_requests = pull_requests.map { |pr| "#{pr["title"]} (#{Formatter.url(pr["html_url"])})" }.join(", ") end diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index fb25328cf7..5bbbd4be1c 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -288,7 +288,7 @@ module SharedEnvExtension gcc_version_name = "gcc@#{version}" gcc = Formulary.factory("gcc") - if gcc.try(:version_suffix) == version + if gcc.respond_to?(:version_suffix) && T.unsafe(gcc).version_suffix == version gcc else Formulary.factory(gcc_version_name) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index e7b757c5e8..0544e7d6f0 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2351,12 +2351,17 @@ class Formula hsh["requirements"] = merge_spec_dependables(requirements).map do |data| req = data[:dependable] req_name = req.name.dup - req_name.prepend("maximum_") if req.try(:comparator) == "<=" + req_name.prepend("maximum_") if req.respond_to?(:comparator) && req.comparator == "<=" + req_version = if req.respond_to?(:version) + req.version + elsif req.respond_to?(:arch) + req.arch + end { "name" => req_name, "cask" => req.cask, "download" => req.download, - "version" => req.try(:version) || req.try(:arch), + "version" => req_version, "contexts" => req.tags, "specs" => data[:specs], } diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 3597cfe82f..487b40710e 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -19,7 +19,6 @@ 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/object/blank" -require "active_support/core_ext/object/try" require "active_support/core_ext/string/exclude" require "active_support/core_ext/string/filters" require "active_support/core_ext/string/indent" diff --git a/Library/Homebrew/lazy_object.rb b/Library/Homebrew/lazy_object.rb index 4dfcbdb4e6..4966f959f8 100644 --- a/Library/Homebrew/lazy_object.rb +++ b/Library/Homebrew/lazy_object.rb @@ -1,6 +1,8 @@ # typed: true # frozen_string_literal: true +require "delegate" + # An object which lazily evaluates its inner block only once a method is called on it. # # @api private diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/object/try.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/object/try.rb deleted file mode 100644 index 999141a993..0000000000 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/object/try.rb +++ /dev/null @@ -1,158 +0,0 @@ -# frozen_string_literal: true - -require "delegate" - -module ActiveSupport - module Tryable #:nodoc: - def try(method_name = nil, *args, &b) - if method_name.nil? && block_given? - if b.arity == 0 - instance_eval(&b) - else - yield self - end - elsif respond_to?(method_name) - public_send(method_name, *args, &b) - end - end - ruby2_keywords(:try) if respond_to?(:ruby2_keywords, true) - - def try!(method_name = nil, *args, &b) - if method_name.nil? && block_given? - if b.arity == 0 - instance_eval(&b) - else - yield self - end - else - public_send(method_name, *args, &b) - end - end - ruby2_keywords(:try!) if respond_to?(:ruby2_keywords, true) - end -end - -class Object - include ActiveSupport::Tryable - - ## - # :method: try - # - # :call-seq: - # try(*a, &b) - # - # Invokes the public method whose name goes as first argument just like - # +public_send+ does, except that if the receiver does not respond to it the - # call returns +nil+ rather than raising an exception. - # - # This method is defined to be able to write - # - # @person.try(:name) - # - # instead of - # - # @person.name if @person - # - # +try+ calls can be chained: - # - # @person.try(:spouse).try(:name) - # - # instead of - # - # @person.spouse.name if @person && @person.spouse - # - # +try+ will also return +nil+ if the receiver does not respond to the method: - # - # @person.try(:non_existing_method) # => nil - # - # instead of - # - # @person.non_existing_method if @person.respond_to?(:non_existing_method) # => nil - # - # +try+ returns +nil+ when called on +nil+ regardless of whether it responds - # to the method: - # - # nil.try(:to_i) # => nil, rather than 0 - # - # Arguments and blocks are forwarded to the method if invoked: - # - # @posts.try(:each_slice, 2) do |a, b| - # ... - # end - # - # The number of arguments in the signature must match. If the object responds - # to the method the call is attempted and +ArgumentError+ is still raised - # in case of argument mismatch. - # - # If +try+ is called without arguments it yields the receiver to a given - # block unless it is +nil+: - # - # @person.try do |p| - # ... - # end - # - # You can also call try with a block without accepting an argument, and the block - # will be instance_eval'ed instead: - # - # @person.try { upcase.truncate(50) } - # - # Please also note that +try+ is defined on +Object+. Therefore, it won't work - # with instances of classes that do not have +Object+ among their ancestors, - # like direct subclasses of +BasicObject+. - - ## - # :method: try! - # - # :call-seq: - # try!(*a, &b) - # - # Same as #try, but raises a +NoMethodError+ exception if the receiver is - # not +nil+ and does not implement the tried method. - # - # "a".try!(:upcase) # => "A" - # nil.try!(:upcase) # => nil - # 123.try!(:upcase) # => NoMethodError: undefined method `upcase' for 123:Integer -end - -class Delegator - include ActiveSupport::Tryable - - ## - # :method: try - # - # :call-seq: - # try(a*, &b) - # - # See Object#try - - ## - # :method: try! - # - # :call-seq: - # try!(a*, &b) - # - # See Object#try! -end - -class NilClass - # Calling +try+ on +nil+ always returns +nil+. - # It becomes especially helpful when navigating through associations that may return +nil+. - # - # nil.try(:name) # => nil - # - # Without +try+ - # @person && @person.children.any? && @person.children.first.name - # - # With +try+ - # @person.try(:children).try(:first).try(:name) - def try(_method_name = nil, *) - nil - end - - # Calling +try!+ on +nil+ always returns +nil+. - # - # nil.try!(:name) # => nil - def try!(_method_name = nil, *) - nil - end -end