Closed rmacklin closed 5 years ago
I can open a PR, but wanted to get thoughts from the maintainers about how they would like to see it implemented.
Here's the current code:
if RUBY_VERSION < '2.5.0' && RUBY_ENGINE == 'ruby'
module Kernel
alias_method :__original_warn, :warn
def warn(*messages)
message = messages.join("\n")
message += "\n" unless message.end_with?("\n")
if DeprecationToolkit::Warning.deprecation_triggered?(message)
ActiveSupport::Deprecation.warn(message)
else
__original_warn(messages)
end
end
end
end
The simplest solution would be to duplicate the patch inside class << self
:
if RUBY_VERSION < '2.5.0' && RUBY_ENGINE == 'ruby'
module Kernel
class << self
alias_method :__original_warn, :warn
def warn(*messages)
message = messages.join("\n")
message += "\n" unless message.end_with?("\n")
if DeprecationToolkit::Warning.deprecation_triggered?(message)
ActiveSupport::Deprecation.warn(message)
else
__original_warn(messages)
end
end
end
alias_method :__original_warn, :warn
def warn(*messages)
message = messages.join("\n")
message += "\n" unless message.end_with?("\n")
if DeprecationToolkit::Warning.deprecation_triggered?(message)
ActiveSupport::Deprecation.warn(message)
else
__original_warn(messages)
end
end
end
end
but please share your preferred implementation.
Thanks a lot for opening the issue. I went ahead and implemented a fix based on your snippet. I credited you in the Changelog
Here is a failing test that demonstrates this:
Kernel.warn
is used in place ofKernel#warn
in places wherewarn
would not resolve toKernel#warn
, e.g. here.