diff --git a/.gitignore b/.gitignore
index 459a668d06..7e87d15850 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,7 +63,6 @@
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/*/
-!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/array/access.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/enumerable.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/file/atomic.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_merge.rb
diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb
index 4bb9aec91c..1f2f4cdc18 100644
--- a/Library/Homebrew/cli/parser.rb
+++ b/Library/Homebrew/cli/parser.rb
@@ -126,9 +126,9 @@ module Homebrew
# Filter out Sorbet runtime type checking method calls.
cmd_location = T.must(caller_locations).select do |location|
T.must(location.path).exclude?("/gems/sorbet-runtime-")
- end.second
- @command_name = cmd_location.label.chomp("_args").tr("_", "-")
- @is_dev_cmd = cmd_location.absolute_path.start_with?(Commands::HOMEBREW_DEV_CMD_PATH)
+ end.fetch(1)
+ @command_name = T.must(cmd_location.label).chomp("_args").tr("_", "-")
+ @is_dev_cmd = T.must(cmd_location.absolute_path).start_with?(Commands::HOMEBREW_DEV_CMD_PATH)
@constraints = []
@conflicts = []
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index 4f9becfad9..17ce9fac20 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -360,7 +360,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
end
if search_query && (uri_query = uri.query.presence)
- components[:query] = URI.decode_www_form(uri_query).map(&:second)
+ components[:query] = URI.decode_www_form(uri_query).map { _1.fetch(1) }
end
else
components[:path] = [url]
diff --git a/Library/Homebrew/extend/array.rb b/Library/Homebrew/extend/array.rb
index 2755ee92bf..468149e00c 100644
--- a/Library/Homebrew/extend/array.rb
+++ b/Library/Homebrew/extend/array.rb
@@ -1,7 +1,18 @@
-# typed: true
+# typed: strict
# frozen_string_literal: true
class Array
+
+ # Equal to self[1].
+ #
+ # %w( a b c d e ).second # => "b"
+ def second = self[1]
+
+ # Equal to self[2].
+ #
+ # %w( a b c d e ).third # => "c"
+ def third = self[2]
+
# Converts the array to a comma-separated sentence where the last element is
# joined by the connector word.
#
@@ -48,6 +59,7 @@ class Array
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ sig { params(words_connector: String, two_words_connector: String, last_word_connector: String).returns(String) }
def to_sentence(words_connector: ", ", two_words_connector: " and ", last_word_connector: " and ")
case length
when 0
diff --git a/Library/Homebrew/extend/array.rbi b/Library/Homebrew/extend/array.rbi
new file mode 100644
index 0000000000..5255357ead
--- /dev/null
+++ b/Library/Homebrew/extend/array.rbi
@@ -0,0 +1,9 @@
+# typed: strict
+
+class Array
+ sig { returns(T.nilable(Elem)) }
+ def second; end
+
+ sig { returns(T.nilable(Elem)) }
+ def third; end
+end
diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb
index d747954e2b..fa07be12e7 100644
--- a/Library/Homebrew/global.rb
+++ b/Library/Homebrew/global.rb
@@ -12,7 +12,6 @@ require "set"
# Only require "core_ext" here to ensure we're only requiring the minimum of
# what we need.
-require "active_support/core_ext/array/access"
require "active_support/core_ext/enumerable"
require "active_support/core_ext/file/atomic"
require "active_support/core_ext/hash/deep_merge"
@@ -71,6 +70,7 @@ HOMEBREW_PULL_OR_COMMIT_URL_REGEX =
HOMEBREW_BOTTLES_EXTNAME_REGEX = /\.([a-z0-9_]+)\.bottle\.(?:(\d+)\.)?tar\.gz$/
require "extend/module"
+require "extend/array"
require "extend/blank"
require "env_config"
require "macos_version"
@@ -130,7 +130,6 @@ module Homebrew
end
require "context"
-require "extend/array"
require "git_repository"
require "extend/pathname"
require "cli/args"
diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb
index d38503bde7..25033917e5 100644
--- a/Library/Homebrew/tab.rb
+++ b/Library/Homebrew/tab.rb
@@ -92,7 +92,7 @@ class Tab
end
if attributes["source"]["spec"].nil?
- version = PkgVersion.parse path.to_s.split("/").second_to_last
+ version = PkgVersion.parse path.to_s.split("/")[-2]
attributes["source"]["spec"] = if version.head?
"head"
else
diff --git a/Library/Homebrew/utils/gems.rb b/Library/Homebrew/utils/gems.rb
index c6762c4985..54c9786e04 100644
--- a/Library/Homebrew/utils/gems.rb
+++ b/Library/Homebrew/utils/gems.rb
@@ -14,7 +14,7 @@ module Homebrew
# Bump this whenever a committed vendored gem is later added to gitignore.
# This will trigger it to reinstall properly if `brew install-bundler-gems` needs it.
- VENDOR_VERSION = 4
+ VENDOR_VERSION = 5
private_constant :VENDOR_VERSION
RUBY_BUNDLE_VENDOR_DIRECTORY = (HOMEBREW_LIBRARY_PATH/"vendor/bundle/ruby").freeze
diff --git a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/array/access.rb b/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/array/access.rb
deleted file mode 100644
index ea01e5891c..0000000000
--- a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/array/access.rb
+++ /dev/null
@@ -1,104 +0,0 @@
-# frozen_string_literal: true
-
-class Array
- # Returns the tail of the array from +position+.
- #
- # %w( a b c d ).from(0) # => ["a", "b", "c", "d"]
- # %w( a b c d ).from(2) # => ["c", "d"]
- # %w( a b c d ).from(10) # => []
- # %w().from(0) # => []
- # %w( a b c d ).from(-2) # => ["c", "d"]
- # %w( a b c ).from(-10) # => []
- def from(position)
- self[position, length] || []
- end
-
- # Returns the beginning of the array up to +position+.
- #
- # %w( a b c d ).to(0) # => ["a"]
- # %w( a b c d ).to(2) # => ["a", "b", "c"]
- # %w( a b c d ).to(10) # => ["a", "b", "c", "d"]
- # %w().to(0) # => []
- # %w( a b c d ).to(-2) # => ["a", "b", "c"]
- # %w( a b c ).to(-10) # => []
- def to(position)
- if position >= 0
- take position + 1
- else
- self[0..position]
- end
- end
-
- # Returns a new array that includes the passed elements.
- #
- # [ 1, 2, 3 ].including(4, 5) # => [ 1, 2, 3, 4, 5 ]
- # [ [ 0, 1 ] ].including([ [ 1, 0 ] ]) # => [ [ 0, 1 ], [ 1, 0 ] ]
- def including(*elements)
- self + elements.flatten(1)
- end
-
- # Returns a copy of the Array excluding the specified elements.
- #
- # ["David", "Rafael", "Aaron", "Todd"].excluding("Aaron", "Todd") # => ["David", "Rafael"]
- # [ [ 0, 1 ], [ 1, 0 ] ].excluding([ [ 1, 0 ] ]) # => [ [ 0, 1 ] ]
- #
- # Note: This is an optimization of Enumerable#excluding that uses Array#-
- # instead of Array#reject for performance reasons.
- def excluding(*elements)
- self - elements.flatten(1)
- end
-
- # Alias for #excluding.
- def without(*elements)
- excluding(*elements)
- end
-
- # Equal to self[1].
- #
- # %w( a b c d e ).second # => "b"
- def second
- self[1]
- end
-
- # Equal to self[2].
- #
- # %w( a b c d e ).third # => "c"
- def third
- self[2]
- end
-
- # Equal to self[3].
- #
- # %w( a b c d e ).fourth # => "d"
- def fourth
- self[3]
- end
-
- # Equal to self[4].
- #
- # %w( a b c d e ).fifth # => "e"
- def fifth
- self[4]
- end
-
- # Equal to self[41]. Also known as accessing "the reddit".
- #
- # (1..42).to_a.forty_two # => 42
- def forty_two
- self[41]
- end
-
- # Equal to self[-3].
- #
- # %w( a b c d e ).third_to_last # => "c"
- def third_to_last
- self[-3]
- end
-
- # Equal to self[-2].
- #
- # %w( a b c d e ).second_to_last # => "d"
- def second_to_last
- self[-2]
- end
-end