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.
This commit is contained in:
Daisuke Aritomo 2025-12-03 03:41:21 +09:00 committed by Hiroshi SHIBATA
parent 2d79cc9bfc
commit ca9c61800b
Notes: git 2026-01-15 08:21:04 +00:00
2 changed files with 9 additions and 0 deletions

View File

@ -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

View File

@ -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