diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index e1058ef5f6..ba8e445c8d 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -5,9 +5,7 @@ end std_trap = trap("INT") { exit! 130 } # no backtrace thanks # check ruby version before requiring any modules. -RUBY_VERSION_SPLIT = RUBY_VERSION.split "." -RUBY_X = RUBY_VERSION_SPLIT[0].to_i -RUBY_Y = RUBY_VERSION_SPLIT[1].to_i +RUBY_X, RUBY_Y, = RUBY_VERSION.split(".").map(&:to_i) if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y < 3) raise "Homebrew must be run under Ruby 2.3! You're running #{RUBY_VERSION}." end diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index d325618631..6c5e295539 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -115,10 +115,8 @@ module Cask command.run!("/bin/launchctl", args: ["list"]).stdout.lines .map { |line| line.chomp.split("\t") } .map { |pid, state, id| [pid.to_i, state.to_i, id] } - .select do |fields| - next if fields[0].zero? - - fields[2] =~ /^#{Regexp.escape(bundle_id)}($|\.\d+)/ + .select do |(pid, _, id)| + pid.nonzero? && id.match?(/^#{Regexp.escape(bundle_id)}($|\.\d+)/) end end diff --git a/Library/Homebrew/cask/dsl/version.rb b/Library/Homebrew/cask/dsl/version.rb index 263ef60006..8941854fe3 100644 --- a/Library/Homebrew/cask/dsl/version.rb +++ b/Library/Homebrew/cask/dsl/version.rb @@ -89,19 +89,19 @@ module Cask end def before_comma - version { split(",", 2)[0] } + version { split(",", 2).first } end def after_comma - version { split(",", 2)[1] } + version { split(",", 2).second } end def before_colon - version { split(":", 2)[0] } + version { split(":", 2).first } end def after_colon - version { split(":", 2)[1] } + version { split(":", 2).second } end def no_dividers diff --git a/Library/Homebrew/cmd/switch.rb b/Library/Homebrew/cmd/switch.rb index 1393e3052f..bf22f484a5 100644 --- a/Library/Homebrew/cmd/switch.rb +++ b/Library/Homebrew/cmd/switch.rb @@ -28,7 +28,7 @@ module Homebrew .map { |d| Keg.new(d).version } .sort .join(", ") - version = ARGV[1] + version = ARGV.second if !version || ARGV.named.length > 2 onoe usage diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb index 86406910c1..3b723a73ec 100644 --- a/Library/Homebrew/cmd/tap.rb +++ b/Library/Homebrew/cmd/tap.rb @@ -45,9 +45,9 @@ module Homebrew elsif ARGV.named.empty? puts Tap.names else - tap = Tap.fetch(ARGV.named[0]) + tap = Tap.fetch(ARGV.named.first) begin - tap.install clone_target: ARGV.named[1], + tap.install clone_target: ARGV.named.second, force_auto_update: force_auto_update?, full_clone: full_clone?, quiet: ARGV.quieter? diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 6e76a4b542..c4fa8b4097 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -512,7 +512,7 @@ module Homebrew # Formulae names can legitimately be uppercase/lowercase/both. name = Regexp.new(formula.name, Regexp::IGNORECASE) reason.sub!(name, "") - first_word = reason.split[0] + first_word = reason.split.first if reason =~ /\A[A-Z]/ && !reason.start_with?(*whitelist) problem <<~EOS @@ -724,7 +724,7 @@ module Homebrew version = Version.parse(stable.url) if version >= Version.create("1.0") - minor_version = version.to_s.split(".", 3)[1].to_i + _, minor_version, = version.to_s.split(".", 3).map(&:to_i) if minor_version.odd? problem "#{stable.version} is a development release" end diff --git a/Library/Homebrew/dev-cmd/extract.rb b/Library/Homebrew/dev-cmd/extract.rb index ae199ceaa6..3e4813fdd8 100644 --- a/Library/Homebrew/dev-cmd/extract.rb +++ b/Library/Homebrew/dev-cmd/extract.rb @@ -120,7 +120,7 @@ module Homebrew # Expect exactly two named arguments: formula and tap raise UsageError if ARGV.named.length != 2 - destination_tap = Tap.fetch(ARGV.named[1]) + destination_tap = Tap.fetch(ARGV.named.second) odie "Cannot extract formula to homebrew/core!" if destination_tap.core_tap? destination_tap.install unless destination_tap.installed? diff --git a/Library/Homebrew/dev-cmd/release-notes.rb b/Library/Homebrew/dev-cmd/release-notes.rb index 8445ee2d58..2a990a8617 100644 --- a/Library/Homebrew/dev-cmd/release-notes.rb +++ b/Library/Homebrew/dev-cmd/release-notes.rb @@ -33,7 +33,7 @@ module Homebrew ).lines.first.chomp odie "Could not find any previous tags!" unless previous_tag - end_ref = ARGV.named[1] || "origin/master" + end_ref = ARGV.named.second || "origin/master" [previous_tag, end_ref].each do |ref| next if quiet_system "git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--verify", "--quiet", ref diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index 7a1ffef27f..c9aec5b31a 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -61,7 +61,7 @@ module Homebrew Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp elsif args.to_tag? tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") - previous_tag = tags.lines[1] + previous_tag = tags.lines.second previous_tag ||= begin if (HOMEBREW_REPOSITORY/".git/shallow").exist? safe_system "git", "fetch", "--tags", "--depth=1" @@ -69,7 +69,7 @@ module Homebrew elsif OS.linux? tags = Utils.popen_read("git tag --list | sort -rV") end - tags.lines[1] + tags.lines.second end previous_tag = previous_tag.to_s.chomp odie "Could not find previous tag in:\n#{tags}" if previous_tag.empty? diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index a72e448b2f..087e95b87c 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -105,7 +105,7 @@ module FormulaClassUnavailableErrorModule end def format_list(class_list) - class_list.map { |klass| klass.name.split("::")[-1] }.join(", ") + class_list.map { |klass| klass.name.split("::").last }.join(", ") end end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index df3fe7d924..290187466d 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -417,7 +417,7 @@ class Formula def aliases @aliases ||= if tap tap.alias_reverse_table[full_name].to_a.map do |a| - a.split("/")[-1] + a.split("/").last end else [] @@ -1371,7 +1371,7 @@ class Formula # an array of all {Formula} names # @private def self.names - @names ||= (core_names + tap_names.map { |name| name.split("/")[-1] }).uniq.sort + @names ||= (core_names + tap_names.map { |name| name.split("/").last }).uniq.sort end # an array of all {Formula} files @@ -1462,7 +1462,7 @@ class Formula # an array of all aliases # @private def self.aliases - @aliases ||= (core_aliases + tap_aliases.map { |name| name.split("/")[-1] }).uniq.sort + @aliases ||= (core_aliases + tap_aliases.map { |name| name.split("/").last }).uniq.sort end # an array of all aliases, , which the tap formulae have the fully-qualified name diff --git a/Library/Homebrew/language/haskell.rb b/Library/Homebrew/language/haskell.rb index ee0a061624..dfe6a0dde6 100644 --- a/Library/Homebrew/language/haskell.rb +++ b/Library/Homebrew/language/haskell.rb @@ -71,9 +71,7 @@ module Language rm_rf Dir[".cabal-sandbox/*packages.conf.d/"] end - def install_cabal_package(*args) - options = args[-1].is_a?(Hash) ? args.pop : {} - + def install_cabal_package(*args, **options) cabal_sandbox do cabal_install_tools(*options[:using]) if options[:using] diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 5efae23011..0e73ff545d 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -17,8 +17,8 @@ class Tap when 1 user, repo = args.first.split("/", 2) when 2 - user = args[0] - repo = args[1] + user = args.first + repo = args.second end if [user, repo].any? { |part| part.nil? || part.include?("/") } diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index fb1d05c60e..2528563a75 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -419,10 +419,10 @@ describe Cask::DSL, :cask do let(:token) { "with-installer-script" } it "allows installer script to be specified" do - expect(cask.artifacts.to_a[0].path).to eq(Pathname("/usr/bin/true")) - expect(cask.artifacts.to_a[0].args[:args]).to eq(["--flag"]) - expect(cask.artifacts.to_a[1].path).to eq(Pathname("/usr/bin/false")) - expect(cask.artifacts.to_a[1].args[:args]).to eq(["--flag"]) + expect(cask.artifacts.to_a.first.path).to eq(Pathname("/usr/bin/true")) + expect(cask.artifacts.to_a.first.args[:args]).to eq(["--flag"]) + expect(cask.artifacts.to_a.second.path).to eq(Pathname("/usr/bin/false")) + expect(cask.artifacts.to_a.second.args[:args]).to eq(["--flag"]) end end diff --git a/Library/Homebrew/test/patch_spec.rb b/Library/Homebrew/test/patch_spec.rb index 1c4ba05a3a..dc1ec2b9b3 100644 --- a/Library/Homebrew/test/patch_spec.rb +++ b/Library/Homebrew/test/patch_spec.rb @@ -86,8 +86,8 @@ describe Patch do ) expect(patches.length).to eq(2) - expect(patches[0].strip).to eq(:p1) - expect(patches[1].strip).to eq(:p1) + expect(patches.first.strip).to eq(:p1) + expect(patches.second.strip).to eq(:p1) end it "can create patches from a :p0 hash" do diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index e2e518c6c1..c09ae260b6 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -53,8 +53,9 @@ RSpec.shared_context "integration test" do def command_id_from_args(args) @command_count ||= 0 pretty_args = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@") - file_and_line = caller[1].sub(/(.*\d+):.*/, '\1') - .sub("#{HOMEBREW_LIBRARY_PATH}/test/", "") + file_and_line = caller.second + .sub(/(.*\d+):.*/, '\1') + .sub("#{HOMEBREW_LIBRARY_PATH}/test/", "") "#{file_and_line}:brew #{pretty_args}:#{@command_count += 1}" end diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 648c3d88b1..832b815ff4 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -54,7 +54,7 @@ module Utils end def resolve_version(bottle_file) - PkgVersion.parse receipt_path(bottle_file).split("/")[1] + PkgVersion.parse receipt_path(bottle_file).split("/").second end def formula_contents(bottle_file, diff --git a/Library/Homebrew/utils/tty.rb b/Library/Homebrew/utils/tty.rb index f52c874d97..8a98cf1a29 100644 --- a/Library/Homebrew/utils/tty.rb +++ b/Library/Homebrew/utils/tty.rb @@ -7,8 +7,8 @@ module Tty def width @width ||= begin - width = `/bin/stty size 2>/dev/null`.split[1] - width = `/usr/bin/tput cols 2>/dev/null`.split[0] if width.to_i.zero? + _, width = `/bin/stty size 2>/dev/null`.split + width, = `/usr/bin/tput cols 2>/dev/null`.split if width.to_i.zero? width ||= 80 width.to_i end diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index f1ac71cbac..b06624a8b6 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -351,7 +351,7 @@ class Version # e.g. https://github.com/JustArchi/ArchiSteamFarm/releases/download/2.3.2.0/ASF.zip # e.g. https://people.gnome.org/~newren/eg/download/1.7.5.2/eg m = %r{/([rvV]_?)?(\d\.\d+(\.\d+){,2})}.match(spec_s) - return m.captures[1] unless m.nil? + return m.captures.second unless m.nil? # e.g. https://www.ijg.org/files/jpegsrc.v8d.tar.gz m = /\.v(\d+[a-z]?)/.match(stem)