New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve documentation about Kernel
monkeypatches
#6217
Conversation
Should we make this appear at https://docs.ruby-lang.org/en/master/Kernel.html#method-i-require instead? It does seem useful there to me. |
Already |
Ah I see! Do you know of any workaround for that? |
I came up is that:
|
Just an idea. diff --git i/lib/rubygems.rb w/lib/rubygems.rb
index 73a9848bf..70e51a996 100644
--- i/lib/rubygems.rb
+++ w/lib/rubygems.rb
@@ -119,10 +119,6 @@
# to avoid deprecation warnings in Ruby 2.7.
UNTAINT = RUBY_VERSION < "2.7" ? :untaint.to_sym : proc {}
- # When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn
- KERNEL_WARN_IGNORES_INTERNAL_ENTRIES = RUBY_ENGINE == "truffleruby" ||
- (RUBY_ENGINE == "ruby" && RUBY_VERSION >= "3.0")
-
##
# An Array of Regexps that match windows Ruby platforms.
@@ -1348,7 +1344,16 @@
Gem::Specification.load_defaults
require_relative "rubygems/core_ext/kernel_gem"
-require_relative "rubygems/core_ext/kernel_require"
+
+path = File.join(__dir__, "rubygems/core_ext/kernel_require.rb")
+# When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn
+if RUBY_ENGINE == "truffleruby" ||
+ (RUBY_ENGINE == "ruby" && RUBY_VERSION >= "3.0")
+ file = "<internal:#{path}>"
+else
require_relative "rubygems/core_ext/kernel_warn"
+ file = path
+end
+module_eval File.read(path), file
require ENV["BUNDLER_SETUP"] if ENV["BUNDLER_SETUP"] && !defined?(Bundler)
diff --git i/lib/rubygems/core_ext/kernel_require.rb w/lib/rubygems/core_ext/kernel_require.rb
index 8064d813e..267cfcd33 100644
--- i/lib/rubygems/core_ext/kernel_require.rb
+++ w/lib/rubygems/core_ext/kernel_require.rb
@@ -17,8 +17,6 @@
private :gem_original_require
end
- file = Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES ? "<internal:#{__FILE__}>" : __FILE__
- module_eval <<'RUBY', file, __LINE__ + 1 # rubocop:disable Style/EvalWithLocation
##
# When RubyGems is required, Kernel#require is replaced with our own which
# is capable of loading gems on demand.
@@ -168,7 +166,6 @@
end
end
end
-RUBY
private :require
diff --git i/lib/rubygems/core_ext/kernel_warn.rb w/lib/rubygems/core_ext/kernel_warn.rb
index f0f173c0b..1f4c77f04 100644
--- i/lib/rubygems/core_ext/kernel_warn.rb
+++ w/lib/rubygems/core_ext/kernel_warn.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-if !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES
-
module Kernel
rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path.
@@ -50,4 +48,3 @@
original_warn.bind(self).call(*messages, **kw)
}
end
-end |
Also |
d51606c
to
27e3419
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels really nice, not only to have this documented at the right place, but also to no longer have our whole require
redefinition wrapped in a heredoc.
Since RDoc does not parse string literals as documents, `eval` the entire file instead of embedding in a here-document. On the contrary, as `gem_original_require` alias is an implementation detail but not for users, it should not be documented.
Kernel
monkeypatches
There was no further feedback here, so I'm merging this, thanks so much @nobu! |
Improve documentation about `Kernel` monkeypatches (cherry picked from commit 1da658d)
What was the end-user or developer problem that led to this PR?
https://bugs.ruby-lang.org/issues/19285
This seems an implementation detail but not for users.
What is your fix for the problem, implemented in this PR?
Hide this comment from RDoc.
Make sure the following tasks are checked