开发者

Selectively silence JRuby warnings

开发者_如何学Python

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

Is there any way to get JRuby to stop complaining about this?


You have a couple options.

First, you can run your program with the -W0 option which will disable all warnings. That's probably not what you want.

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"

Running this with JRuby 1.5.0 correctly warns me about the reinitialized constant and correctly suppresses the GC.disable warning.


If you switch from ruby-mysql to activerecord-jdbcmysql-adapter, you can avoid this warning entirely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜