选择性地使JRuby警告静音 [英] Selectively silence JRuby warnings
问题描述
我正在使用JRuby下的ruby-mysql库,并收到以下警告:
I'm using the ruby-mysql library under JRuby and get the following warnings:
/mysql/protocol.rb:530 warning: GC.disable does nothing on JRuby
有没有办法让JRuby停止抱怨呢?
Is there any way to get JRuby to stop complaining about this?
推荐答案
您有两种选择.
首先,您可以使用-W0
选项运行程序,该选项将禁用 all 警告.那可能不是您想要的.
First, you can run your program with the -W0
option which will disable all warnings. That's probably not what you want.
但是,应用-W0
与将$VERBOSE
设置为nil
相同-因此,我们可以在希望抑制警告的代码周围简单地执行此操作.这是第二个也是更可取的选择.
However, applying -W0
is the same as setting $VERBOSE
to nil
-- so we can simply do that around the code where we want to suppress warnings. This is the second and much more preferable option.
def suppress_all_warnings
old_verbose = $VERBOSE
begin
$VERBOSE = nil
yield if block_given?
ensure
# always re-set to old value, even if block raises an exception
$VERBOSE = old_verbose
end
end
puts "Starting"
MyConst = 1
MyConst = 2
suppress_all_warnings do
GC.disable
end
puts "Done"
使用JRuby 1.5.0正确运行此操作会警告我有关已重新初始化的常量的信息,并正确禁止显示GC.disable
警告.
Running this with JRuby 1.5.0 correctly warns me about the reinitialized constant and correctly suppresses the GC.disable
warning.
这篇关于选择性地使JRuby警告静音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!