选择性地使JRuby警告静音 [英] Selectively silence JRuby warnings

查看:80
本文介绍了选择性地使JRuby警告静音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆