我正在尝试动态重新定义gem的常量,所以我不需要修改gem本身。
require 'xmlrpc/client'
XMLRPC::Config.const_set("ENABLE_NIL_PARSER", true)
warning: already initialized constant ENABLE_NIL_PARSER
是否有可能摆脱警告?
答案 0 :(得分:6)
简单方法:
v, $VERBOSE = $VERBOSE, nil
# code goes here
$VERBOSE = v
答案 1 :(得分:5)
你甚至可以将它包装在一个块中,比如
def ignoring_warnings(&block)
begin
v, $VERBOSE = $VERBOSE, nil
block.call if block
ensure
$VERBOSE = v
end
end