2010-05-21 39 views
2

我使用的紅寶石MySQL庫在JRuby下,並得到以下警告:選擇性沉默的JRuby警告

/mysql/protocol.rb:530 warning: GC.disable does nothing on JRuby

有沒有什麼辦法讓JRuby中不停抱怨呢?

回答

6

你有幾個選項。

首先,您可以使用-W0選項運行程序,該選項將禁用所有警告。這可能不是你想要的。

但是,應用-W0與設置$VERBOSEnil相同 - 所以我們可以簡單地在要禁止警告的代碼周圍執行此操作。這是第二個也是更可取的選擇。

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警告。

+0

非常好,內容翔實的答案。謝謝! – makenai 2010-05-21 05:25:54