Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rubygems/rubygems] Let RDoc parse the doc of
Kernel#require
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. rubygems/rubygems@cad4cf16cf
- Loading branch information
Showing
3 changed files
with
47 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
if !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES | ||
module Kernel | ||
rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path. | ||
|
||
module Kernel | ||
rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path. | ||
original_warn = instance_method(:warn) | ||
|
||
original_warn = instance_method(:warn) | ||
remove_method :warn | ||
|
||
class << self | ||
remove_method :warn | ||
end | ||
|
||
class << self | ||
remove_method :warn | ||
module_function define_method(:warn) {|*messages, **kw| | ||
unless uplevel = kw[:uplevel] | ||
if Gem.java_platform? && RUBY_VERSION < "3.1" | ||
return original_warn.bind(self).call(*messages) | ||
else | ||
return original_warn.bind(self).call(*messages, **kw) | ||
end | ||
end | ||
|
||
module_function define_method(:warn) {|*messages, **kw| | ||
unless uplevel = kw[:uplevel] | ||
if Gem.java_platform? && RUBY_VERSION < "3.1" | ||
return original_warn.bind(self).call(*messages) | ||
else | ||
return original_warn.bind(self).call(*messages, **kw) | ||
# Ensure `uplevel` fits a `long` | ||
uplevel, = [uplevel].pack("l!").unpack("l!") | ||
|
||
if uplevel >= 0 | ||
start = 0 | ||
while uplevel >= 0 | ||
loc, = caller_locations(start, 1) | ||
unless loc | ||
# No more backtrace | ||
start += uplevel | ||
break | ||
end | ||
end | ||
|
||
# Ensure `uplevel` fits a `long` | ||
uplevel, = [uplevel].pack("l!").unpack("l!") | ||
|
||
if uplevel >= 0 | ||
start = 0 | ||
while uplevel >= 0 | ||
loc, = caller_locations(start, 1) | ||
unless loc | ||
# No more backtrace | ||
start += uplevel | ||
break | ||
end | ||
start += 1 | ||
|
||
start += 1 | ||
|
||
if path = loc.path | ||
unless path.start_with?(rubygems_path) || path.start_with?("<internal:") | ||
# Non-rubygems frames | ||
uplevel -= 1 | ||
end | ||
if path = loc.path | ||
unless path.start_with?(rubygems_path) || path.start_with?("<internal:") | ||
# Non-rubygems frames | ||
uplevel -= 1 | ||
end | ||
end | ||
kw[:uplevel] = start | ||
end | ||
kw[:uplevel] = start | ||
end | ||
|
||
original_warn.bind(self).call(*messages, **kw) | ||
} | ||
end | ||
original_warn.bind(self).call(*messages, **kw) | ||
} | ||
end |