mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
kernel_warn.rb: skip kernel_require.rb
* lib/rubygems/core_ext/kernel_warn.rb (Kernel#warn): skip kernel_require.rb's frames when `uplevel` option is given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
85e5424a46
commit
7fbe79f63a
3 changed files with 40 additions and 0 deletions
21
lib/rubygems/core_ext/kernel_warn.rb
Executable file
21
lib/rubygems/core_ext/kernel_warn.rb
Executable file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
if RUBY_VERSION >= "2.5"
|
||||
module Kernel
|
||||
path = "#{__dir__}/"
|
||||
original_warn = instance_method(:warn)
|
||||
Module.new {define_method(:warn, original_warn)}
|
||||
original_warn = method(:warn)
|
||||
|
||||
module_function define_method(:warn) {|message, uplevel: nil|
|
||||
if uplevel
|
||||
while (loc, = caller_locations(uplevel, 1); loc && loc.path.start_with?(path))
|
||||
uplevel += 1
|
||||
end
|
||||
original_warn.call(message, uplevel: uplevel + 1)
|
||||
else
|
||||
original_warn.call(message)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue