mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
f48655d04d
I noticed that some files in rubygems were executable, and I could think of no reason why they should be. In general, I think ruby files should never have the executable bit set unless they include a shebang, so I run the following command over the whole repo: ```bash find . -name '*.rb' -type f -executable -exec bash -c 'grep -L "^#!" $1 || chmod -x $1' _ {} \; ```
51 lines
1.2 KiB
Ruby
51 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# `uplevel` keyword argument of Kernel#warn is available since ruby 2.5.
|
|
if RUBY_VERSION >= "2.5"
|
|
|
|
module Kernel
|
|
path = "#{__dir__}/" # Frames to be skipped start with this path.
|
|
|
|
# Suppress "method redefined" warning
|
|
original_warn = instance_method(:warn)
|
|
Module.new {define_method(:warn, original_warn)}
|
|
|
|
original_warn = method(:warn)
|
|
|
|
module_function define_method(:warn) {|*messages, **kw|
|
|
unless uplevel = kw[:uplevel]
|
|
if Gem.java_platform?
|
|
return original_warn.call(*messages)
|
|
else
|
|
return original_warn.call(*messages, **kw)
|
|
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
|
|
|
|
unless loc.path.start_with?(path)
|
|
# Non-rubygems frames
|
|
uplevel -= 1
|
|
end
|
|
end
|
|
uplevel = start
|
|
end
|
|
|
|
kw[:uplevel] = uplevel
|
|
original_warn.call(*messages, **kw)
|
|
}
|
|
end
|
|
end
|