From ca9c61800bce426ea9c4b15911a4f639370f3ec4 Mon Sep 17 00:00:00 2001 From: Daisuke Aritomo Date: Wed, 3 Dec 2025 03:41:21 +0900 Subject: [PATCH] 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. --- lib/bundled_gems.rb | 4 ++++ prelude.rb | 5 +++++ 2 files changed, 9 insertions(+) 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 7b5a766898..163aa5c3e5 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