summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Aritomo <osyoyu@osyoyu.com>2025-12-03 03:41:21 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2026-01-20 10:49:33 -0800
commita3dc71eb5fe8ae7c411067a58ec91201fec240ee (patch)
treed14c9b3d0794f8137f558163274e125e07ab4ad8
parent310da6cd91ccdab82f5cb9cef482f5cf9da1bb19 (diff)
Suppress bundled gem warning on `binding.irb'
This patch silences the "this won't work in the next version of Ruby" warning displayed when irb is autoloaded via `binding.irb`. main.rb:1: warning: irb used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0. You can add irb to your Gemfile or gemspec to fix this error. /.../irb.rb:9: warning: reline used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0. You can add reline to your Gemfile or gemspec to fix this error. From: main.rb @ line 1 : => 1: binding.irb /.../input-method.rb:284: warning: rdoc used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0. You can add rdoc to your Gemfile or gemspec to fix this error. This warning is incorrect and misleading: users should not need to include irb (and its dependencies) to their Gemfiles to use `binding.irb`, even in future versions of Ruby. It is agreed that the runtime takes care of that.
-rw-r--r--lib/bundled_gems.rb4
-rw-r--r--prelude.rb5
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/bundled_gems.rb b/lib/bundled_gems.rb
index f6fdad21a1..85f23b2596 100644
--- a/lib/bundled_gems.rb
+++ b/lib/bundled_gems.rb
@@ -122,6 +122,10 @@ module Gem::BUNDLED_GEMS # :nodoc:
false
end
+ if suppress_list = Thread.current[:__bundled_gems_warning_suppression]
+ return if suppress_list.include?(name) || suppress_list.include?(feature)
+ end
+
return if specs.include?(name)
# Don't warn if a hyphenated gem provides this feature
diff --git a/prelude.rb b/prelude.rb
index 36da381804..249d0ecf7b 100644
--- a/prelude.rb
+++ b/prelude.rb
@@ -1,6 +1,9 @@
class Binding
# :nodoc:
def irb(...)
+ suppress = Thread.current[:__bundled_gems_warning_suppression]
+ Thread.current[:__bundled_gems_warning_suppression] = ['irb', 'reline', 'rdoc']
+
begin
require 'irb'
rescue LoadError, Gem::LoadError
@@ -8,6 +11,8 @@ class Binding
require 'irb'
end
irb(...)
+ ensure
+ Thread.current[:__bundled_gems_warning_suppression] = suppress
end
# suppress redefinition warning