From a70adce1ce5fae8eaae385214ac0d2e7d17c1103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 4 Sep 2024 22:01:03 +0200 Subject: [PATCH] Only `warn` about bundled gems when require succeeds --- lib/bundled_gems.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/bundled_gems.rb b/lib/bundled_gems.rb index a0e2c4ef8c..f819134c96 100644 --- a/lib/bundled_gems.rb +++ b/lib/bundled_gems.rb @@ -69,14 +69,17 @@ module Gem::BUNDLED_GEMS [::Kernel.singleton_class, ::Kernel].each do |kernel_class| kernel_class.send(:alias_method, :no_warning_require, :require) kernel_class.send(:define_method, :require) do |name| - if message = ::Gem::BUNDLED_GEMS.warning?(name, specs: spec_names) + result = kernel_class.send(:no_warning_require, name) + + if result && message = ::Gem::BUNDLED_GEMS.warning?(name, specs: spec_names) if ::Gem::BUNDLED_GEMS.uplevel > 0 Kernel.warn message, uplevel: ::Gem::BUNDLED_GEMS.uplevel else Kernel.warn message end end - kernel_class.send(:no_warning_require, name) + + result end if kernel_class == ::Kernel kernel_class.send(:private, :require)