Ruby 如何在警告时退出?
Ruby how to make exit on warning?
我读到可以通过重新定义 Kernel.warn 让 Ruby 在警告时退出,但我不知道如何做。如何让 Ruby 在警告时退出?请提供工作示例。
这是一种覆盖 Kernel#warn
的方法
module Kernel
alias orig_warn warn
def warn args
orig_warn args
exit
end
end
puts "Foo"
warn "Bar"
puts "Don't want to see this"
我读到可以通过重新定义 Kernel.warn 让 Ruby 在警告时退出,但我不知道如何做。如何让 Ruby 在警告时退出?请提供工作示例。
这是一种覆盖 Kernel#warn
module Kernel
alias orig_warn warn
def warn args
orig_warn args
exit
end
end
puts "Foo"
warn "Bar"
puts "Don't want to see this"