Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试动态地重新定义 gem 的常量,所以我不需要修改 gem 本身。
require 'xmlrpc/client' XMLRPC::Config.const_set("ENABLE_NIL_PARSER", true) warning: already initialized constant ENABLE_NIL_PARSER
是否有可能摆脱警告?
简单的方法:
v, $VERBOSE = $VERBOSE, nil # code goes here $VERBOSE = v
你甚至可以将它包裹在一个块中,像这样
def ignoring_warnings(&block) begin v, $VERBOSE = $VERBOSE, nil block.call if block ensure $VERBOSE = v end end