diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb
index 532d9f3c3cc8afdeb5e133526d16c2e53cfb4345..8fce9636ad8f37d73f104a4f96c60b8a4316c055 100644
--- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb
+++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb
@@ -56,7 +56,7 @@ module Hbc
 
     class FromURILoader < FromPathLoader
       def self.can_load?(ref)
-        ref.to_s.match?(::URI.regexp)
+        ref.to_s.match?(::URI::DEFAULT_PARSER.make_regexp)
       end
 
       attr_reader :url
diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb
index 2dda476277be0a03cea3b10bc0074170f43478a1..3824b9761fd339b4b57e87a739706eee5ff78212 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl.rb
@@ -161,7 +161,7 @@ module Hbc
         begin
           DSL::Container.new(*args).tap do |container|
             # TODO: remove this backward-compatibility section after removing nested_container
-            if container && container.nested
+            if container&.nested
               artifacts[:nested_container] << Artifact::NestedContainer.new(cask, container.nested)
             end
           end
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index b9c34e3a1d2059dfe5d7f0026527831f5923ec65..01aae935dfa7fb78e4b988953db016336ae93e5e 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -159,7 +159,7 @@ module Hbc
       odebug "Extracting primary container"
 
       FileUtils.mkdir_p @cask.staged_path
-      container = if @cask.container && @cask.container.type
+      container = if @cask.container&.type
         Container.from_type(@cask.container.type)
       else
         Container.for_path(@downloaded_path, @command)
@@ -361,7 +361,7 @@ module Hbc
 
       savedir = @cask.metadata_subdir("Casks", timestamp: :now, create: true)
       FileUtils.copy @cask.sourcefile_path, savedir
-      old_savedir.rmtree unless old_savedir.nil?
+      old_savedir&.rmtree
     end
 
     def uninstall
diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb
index b735ae4f9c046b38045e13f80e12dca1f82489de..be083c29ef82d7d49a8a95eb8305864e02d5d1c4 100644
--- a/Library/Homebrew/cask/lib/hbc/system_command.rb
+++ b/Library/Homebrew/cask/lib/hbc/system_command.rb
@@ -61,7 +61,7 @@ module Hbc
     end
 
     def assert_success
-      return if processed_status && processed_status.success?
+      return if processed_status&.success?
       raise CaskCommandFailedError.new(command, processed_output[:stdout], processed_output[:stderr], processed_status)
     end
 
diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb
index 578b292fabd5632c748b64edb3dc69825106ef42..1849ea79b336350b8c27bd20c4499bae1f856ddf 100644
--- a/Library/Homebrew/caveats.rb
+++ b/Library/Homebrew/caveats.rb
@@ -163,7 +163,7 @@ class Caveats
 
   def plist_caveats
     s = []
-    if f.plist || (keg && keg.plist_installed?)
+    if f.plist || (keg&.plist_installed?)
       plist_domain = f.plist_path.basename(".plist")
 
       # we readlink because this path probably doesn't exist since caveats
diff --git a/Library/Homebrew/cmd/unlinkapps.rb b/Library/Homebrew/cmd/unlinkapps.rb
index 7cae97e27cc2c84f0eb976063ac31b4903c2b54f..56dba3603c3f080be5c8c5dfb72dcc4522783414 100644
--- a/Library/Homebrew/cmd/unlinkapps.rb
+++ b/Library/Homebrew/cmd/unlinkapps.rb
@@ -77,7 +77,7 @@ module Homebrew
   def unlinkapps_unlink?(target_app, opts = {})
     # Skip non-symlinks and symlinks that don't point into the Homebrew prefix.
     app = target_app.readlink.to_s if target_app.symlink?
-    return false unless app && app.start_with?(*UNLINKAPPS_PREFIXES)
+    return false unless app&.start_with?(*UNLINKAPPS_PREFIXES)
 
     if opts.fetch(:prune, false)
       !File.exist?(app) # Remove only broken symlinks in prune mode.
diff --git a/Library/Homebrew/debrew/irb.rb b/Library/Homebrew/debrew/irb.rb
index f974037820a9dc18fe96aca3af46fffe8d540113..069dbe67606e0ea5844b4373f6dc08e56f97ae1d 100644
--- a/Library/Homebrew/debrew/irb.rb
+++ b/Library/Homebrew/debrew/irb.rb
@@ -16,7 +16,7 @@ module IRB
       workspace = WorkSpace.new(binding)
       irb = Irb.new(workspace)
 
-      @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
+      @CONF[:IRB_RC]&.call(irb.context)
       @CONF[:MAIN_CONTEXT] = irb.context
 
       trap("SIGINT") do
diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb
index d7d5ec59c0812fa66f96b081dbdc9ff8c233c232..0fbc2625b115b3a8d098902f8b7f2a0f44924ffc 100644
--- a/Library/Homebrew/dependency.rb
+++ b/Library/Homebrew/dependency.rb
@@ -51,7 +51,7 @@ class Dependency
   end
 
   def modify_build_environment
-    env_proc.call unless env_proc.nil?
+    env_proc&.call
   end
 
   def inspect
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb
index 743b9484ef4101da6da96a202acc3db3f4f5c096..1fb89c3a4ba2a10f5bb00a39172f1d586220dcd3 100644
--- a/Library/Homebrew/dev-cmd/audit.rb
+++ b/Library/Homebrew/dev-cmd/audit.rb
@@ -707,7 +707,7 @@ class FormulaAuditor
     end
 
     stable = formula.stable
-    case stable && stable.url
+    case stable&.url
     when /[\d\._-](alpha|beta|rc\d)/
       matched = Regexp.last_match(1)
       version_prefix = stable.version.to_s.sub(/\d+$/, "")
@@ -1018,7 +1018,7 @@ class FormulaAuditor
   def audit_reverse_migration
     # Only enforce for new formula being re-added to core and official taps
     return unless @strict
-    return unless formula.tap && formula.tap.official?
+    return unless formula.tap&.official?
     return unless formula.tap.tap_migrations.key?(formula.name)
 
     problem <<-EOS.undent
diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb
index d8aefc4c0d220af97a6d61d60d77448fd4d1c3c4..577924a3400897011e91f35c65f2d00874386e58 100644
--- a/Library/Homebrew/dev-cmd/bottle.rb
+++ b/Library/Homebrew/dev-cmd/bottle.rb
@@ -283,7 +283,7 @@ module Homebrew
         raise
       ensure
         ignore_interrupts do
-          original_tab.write if original_tab
+          original_tab&.write
           unless ARGV.include? "--skip-relocation"
             keg.replace_placeholders_with_locations changed_files
           end
diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb
index 521c7630232e26b6523d9141ef9d8b821920e9f4..87a239b986b417913f2bb5ed4c6ef85b827b46f7 100644
--- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb
+++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb
@@ -124,7 +124,7 @@ module Homebrew
       Formula.each do |f|
         if is_devel && f.devel && f.devel.url && f.devel.url.match(base_url)
           guesses << f
-        elsif f.stable && f.stable.url && f.stable.url.match(base_url)
+        elsif f.stable&.url && f.stable.url.match(base_url)
           guesses << f
         end
       end
diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb
index a8f35531f9e11ebb97cbf6b7161ec7015f16fc4a..931cba07f58a8381b6081ce8e0952a2153569afa 100644
--- a/Library/Homebrew/dev-cmd/pull.rb
+++ b/Library/Homebrew/dev-cmd/pull.rb
@@ -75,7 +75,7 @@ module Homebrew
         tap = CoreTap.instance
       elsif (testing_match = arg.match %r{/job/Homebrew.*Testing/(\d+)/})
         tap = ARGV.value("tap")
-        tap = if tap && tap.start_with?("homebrew/")
+        tap = if tap&.start_with?("homebrew/")
           Tap.fetch("homebrew", tap.strip_prefix("homebrew/"))
         elsif tap
           odie "Tap option did not start with \"homebrew/\": #{tap}"
@@ -350,7 +350,7 @@ module Homebrew
       files << Regexp.last_match(1) if line =~ %r{^\+\+\+ b/(.*)}
     end
     files.each do |file|
-      if tap && tap.formula_file?(file)
+      if tap&.formula_file?(file)
         formula_name = File.basename(file, ".rb")
         formulae << formula_name unless formulae.include?(formula_name)
       else
diff --git a/Library/Homebrew/dev-cmd/release-notes.rb b/Library/Homebrew/dev-cmd/release-notes.rb
index e578869bf7e11ed263025f1b263aea2988581069..4960239565de4c5f3f981c8efbd11f38caf90590 100644
--- a/Library/Homebrew/dev-cmd/release-notes.rb
+++ b/Library/Homebrew/dev-cmd/release-notes.rb
@@ -10,10 +10,8 @@ module Homebrew
 
   def release_notes
     previous_tag = ARGV.named.first
-    unless previous_tag
-      previous_tag = Utils.popen_read("git tag --list --sort=-version:refname")
+    previous_tag ||= Utils.popen_read("git tag --list --sort=-version:refname")
                           .lines.first.chomp
-    end
     odie "Could not find any previous tags!" unless previous_tag
 
     end_ref = ARGV.named[1] || "origin/master"
diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb
index ceb6ad4d1d5c68d4931f306a2f5a642ed6d5596b..88aa4dbc90cced1a1b112a8a1a6b2515fb621102 100644
--- a/Library/Homebrew/diagnostic.rb
+++ b/Library/Homebrew/diagnostic.rb
@@ -522,7 +522,7 @@ module Homebrew
         homebrew_owned = @found.all? do |path|
           Pathname.new(path).realpath.to_s.start_with? "#{HOMEBREW_CELLAR}/gettext"
         end
-        return if gettext && gettext.linked_keg.directory? && homebrew_owned
+        return if gettext&.linked_keg&.directory? && homebrew_owned
 
         inject_file_list @found, <<-EOS.undent
           gettext files detected at a system prefix.
@@ -540,7 +540,7 @@ module Homebrew
         rescue
           nil
         end
-        if libiconv && libiconv.linked_keg.directory?
+        if libiconv&.linked_keg&.directory?
           unless libiconv.keg_only?
             <<-EOS.undent
               A libiconv formula is installed and linked.
diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb
index daa5306faf55f1c50d73e8fcfecab590602099a8..63a0f3e40b07f7f732e2ef2d08aeac70dcb6de35 100644
--- a/Library/Homebrew/extend/ARGV.rb
+++ b/Library/Homebrew/extend/ARGV.rb
@@ -144,7 +144,7 @@ module HomebrewArgvExtension
   def value(name)
     arg_prefix = "--#{name}="
     flag_with_value = find { |arg| arg.start_with?(arg_prefix) }
-    flag_with_value.strip_prefix(arg_prefix) if flag_with_value
+    flag_with_value&.strip_prefix(arg_prefix)
   end
 
   # Returns an array of values that were given as a comma-separated list.
@@ -236,7 +236,7 @@ module HomebrewArgvExtension
 
   def bottle_arch
     arch = value "bottle-arch"
-    arch.to_sym if arch
+    arch&.to_sym
   end
 
   def build_from_source?
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 2f0c913c2168dc50354cf6e40d1803a28e84071a..69a4cd5aafaaf8464fb9b360fe2f85153221fd9d 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -472,7 +472,7 @@ class Formula
     return true if devel && tab.devel_version && tab.devel_version < devel.version
 
     if options[:fetch_head]
-      return false unless head && head.downloader.is_a?(VCSDownloadStrategy)
+      return false unless head&.downloader.is_a?(VCSDownloadStrategy)
       downloader = head.downloader
       downloader.shutup! unless ARGV.verbose?
       downloader.commit_outdated?(version.version.commit)
@@ -1115,8 +1115,8 @@ class Formula
 
   # @private
   def unlock
-    @lock.unlock unless @lock.nil?
-    @oldname_lock.unlock unless @oldname_lock.nil?
+    @lock&.unlock
+    @oldname_lock&.unlock
   end
 
   def migration_needed?
@@ -1440,7 +1440,7 @@ class Formula
   # True if this formula is provided by Homebrew itself
   # @private
   def core_formula?
-    tap && tap.core_tap?
+    tap&.core_tap?
   end
 
   # True if this formula is provided by external Tap
@@ -1525,10 +1525,10 @@ class Formula
       "oldname" => oldname,
       "aliases" => aliases,
       "versions" => {
-        "stable" => (stable.version.to_s if stable),
+        "stable" => stable&.version.to_s,
         "bottle" => bottle ? true : false,
-        "devel" => (devel.version.to_s if devel),
-        "head" => (head.version.to_s if head),
+        "devel" => devel&.version.to_s,
+        "head" => head&.version.to_s,
       },
       "revision" => revision,
       "version_scheme" => version_scheme,
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb
index e955dcf0743797ab996414968e4ccbd906091299..68816a78246ccbd8bb093716f28f94a90d0df437 100644
--- a/Library/Homebrew/formula_installer.rb
+++ b/Library/Homebrew/formula_installer.rb
@@ -560,7 +560,7 @@ class FormulaInstaller
     end
     raise
   else
-    ignore_interrupts { tmp_keg.rmtree if tmp_keg && tmp_keg.directory? }
+    ignore_interrupts { tmp_keg.rmtree if tmp_keg&.directory? }
   end
 
   def caveats
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index 92eab7ad31c78c3eaa8b2736ca554bae960dea40..677a97c85b795ec704e5f011e2e46a325b13cffa 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -338,7 +338,7 @@ class Keg
       dir if dir.directory? && dir.children.any? { |f| f.basename.to_s.start_with?("_") }
     when :fish then path/"share/fish/vendor_completions.d"
     end
-    dir && dir.directory? && !dir.children.empty?
+    dir&.directory? && !dir.children.empty?
   end
 
   def functions_installed?(shell)
diff --git a/Library/Homebrew/language/python.rb b/Library/Homebrew/language/python.rb
index 0f8e3a4e627ad966e83a4c88106d8abc839f4487..bfec556d03a4a1b7752cdc9da9a6c881076eadfe 100644
--- a/Library/Homebrew/language/python.rb
+++ b/Library/Homebrew/language/python.rb
@@ -23,7 +23,7 @@ module Language
         else
           homebrew_site_packages(version)
         end
-        block.call python, version if block
+        block&.call python, version
       end
       ENV["PYTHONPATH"] = original_pythonpath
     end
diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb
index d3e5cb38caceb9442b5253e5ccb0f189cb6dc9f5..15c301f994a169be70293a23f3c6bd3417382d77 100644
--- a/Library/Homebrew/os/mac.rb
+++ b/Library/Homebrew/os/mac.rb
@@ -104,7 +104,7 @@ module OS
     # Returns the path to an SDK or nil, following the rules set by #sdk.
     def sdk_path(v = nil)
       s = sdk(v)
-      s.path unless s.nil?
+      s&.path
     end
 
     # See these issues for some history:
diff --git a/Library/Homebrew/requirements/java_requirement.rb b/Library/Homebrew/requirements/java_requirement.rb
index ab6dca51df1713aca5075eec5e7de1e817fadd88..de3a33eb45ad94c999760ca394406f591b88cab9 100644
--- a/Library/Homebrew/requirements/java_requirement.rb
+++ b/Library/Homebrew/requirements/java_requirement.rb
@@ -69,14 +69,14 @@ class JavaRequirement < Requirement
     rescue FormulaUnavailableError
       nil
     end
-    javas << jdk.bin/"java" if jdk && jdk.installed?
+    javas << jdk.bin/"java" if jdk&.installed?
     javas << which("java")
     javas
   end
 
   def preferred_java
     possible_javas.detect do |java|
-      next false unless java && java.executable?
+      next false unless java&.executable?
       next true unless @version
       next true if satisfies_version(java)
     end
diff --git a/Library/Homebrew/requirements/ruby_requirement.rb b/Library/Homebrew/requirements/ruby_requirement.rb
index acc65592482d4707de666579abb7478a5632a83e..a9ec8c42d27803ab0dc9acc342d6b10dfe953cbd 100644
--- a/Library/Homebrew/requirements/ruby_requirement.rb
+++ b/Library/Homebrew/requirements/ruby_requirement.rb
@@ -41,9 +41,7 @@ class RubyRequirement < Requirement
   def rubies
     rubies = which_all("ruby")
     ruby_formula = Formula["ruby"]
-    if ruby_formula && ruby_formula.installed?
-      rubies.unshift ruby_formula.bin/"ruby"
-    end
+    rubies.unshift ruby_formula.bin/"ruby" if ruby_formula&.installed?
     rubies.uniq
   end
 
diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb
index 8c662857e3e3e13b8af129bd3557501e1f554b07..7d23e59664ae3f41a1ecaba323e64b4e227d3056 100644
--- a/Library/Homebrew/sandbox.rb
+++ b/Library/Homebrew/sandbox.rb
@@ -167,7 +167,7 @@ class Sandbox
 
     def add_rule(rule)
       s = "("
-      s << ((rule[:allow]) ? "allow" : "deny")
+      s << (rule[:allow] ? "allow" : "deny")
       s << " #{rule[:operation]}"
       s << " (#{rule[:filter]})" if rule[:filter]
       s << " (with #{rule[:modifier]})" if rule[:modifier]
diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb
index e7df8835613c4165f8d2d601032587e1da8d3099..af19cabe6799eec3f28bf9b6ef499307f125c6b0 100644
--- a/Library/Homebrew/tab.rb
+++ b/Library/Homebrew/tab.rb
@@ -324,7 +324,7 @@ class Tab < OpenStruct
       "poured_from_bottle" => poured_from_bottle,
       "installed_as_dependency" => installed_as_dependency,
       "installed_on_request" => installed_on_request,
-      "changed_files" => changed_files && changed_files.map(&:to_s),
+      "changed_files" => changed_files&.map(&:to_s),
       "time" => time,
       "source_modified_time" => source_modified_time.to_i,
       "HEAD" => self.HEAD,