如何摆脱红宝石的警告:已经初始化常数

时间:2012-09-22 00:00:28

标签: ruby xml-rpc

我正在尝试动态重新定义gem的常量,所以我不需要修改gem本身。

require 'xmlrpc/client'

XMLRPC::Config.const_set("ENABLE_NIL_PARSER", true)

warning: already initialized constant ENABLE_NIL_PARSER

是否有可能摆脱警告?

2 个答案:

答案 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