use*_*428 0 ruby deprecation-warning
(这与此问题有关)。
在找不到时间更新代码之前,如何抑制Ruby中的弃用警告?示例:下面的命令将生成一个不建议使用的触发器警告(该命令本身是无稽之谈;我只想提供一个语法上正确的最小示例):
ruby -v -e '0 if /a/.../b/'
Run Code Online (Sandbox Code Playgroud)
我已经试过了
ruby -e '$VERBOSE=nil;0 if /a/.../b/'
Run Code Online (Sandbox Code Playgroud)
并且,在安装警告宝石后,
ruby -e 'require "warning";; Warning.ignore(/deprecated/) 0 if /a/.../b/'
Run Code Online (Sandbox Code Playgroud)
但是警告仍会打印到stderr。我不想将整个stderr重定向到bit bucket,因为我不想丢失重要消息。
The warning is generated by the parser before the code is evaluated. That includes your Warning.ignore code, so the config isn't ready when the warning occurs.
You can move that code into a separate file:
# warn.rb
require 'warning'
Warning.ignore(/deprecated/)
Run Code Online (Sandbox Code Playgroud)
and load it via -r:
$ ruby -r./warn.rb -e '0 if /a/.../b/'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
182 次 |
| 最近记录: |