How to get rid of a ruby ​​warning: an already initialized constant

I am trying to override the gem constant dynamically, so I do not need to change the stone itself.

require 'xmlrpc/client' XMLRPC::Config.const_set("ENABLE_NIL_PARSER", true) warning: already initialized constant ENABLE_NIL_PARSER 

Can I get rid of the warning?

+4
source share
2 answers

A simple way:

 v, $VERBOSE = $VERBOSE, nil # code goes here $VERBOSE = v 
+6
source

You can even wrap it in a block like this

 def ignoring_warnings(&block) begin v, $VERBOSE = $VERBOSE, nil block.call if block ensure $VERBOSE = v end end 
+5
source

Source: https://habr.com/ru/post/1435603/


All Articles