Project

General

Profile

Feature #16699

Updated by sawa (Tsuyoshi Sawada) about 4 years ago

I would like to make In ruby it possible to briefly enable or disable particular warnings: those related to modifying a constant or a method. 

 It is possible to silence a specific warning as in: warning, such as: 

     SOME_CONSTANT = 42 
     old_verbose_value = $VERBOSE 
     $VERBOSE = nil 
     SOME_CONSTANT = 24 
     $VERBOSE = old_verbose_value 

 I recently needed to do so to redefine for re-defining a method. I had to add an instance 
 variable to that method. There are alternatives, e.g. e. g. including a module, or 
 subclassing, but I actually really wanted to just redefine re-define the method as is, as-is, 
 without incurring a warning message on the command line. commandline. So I would like to 
 make that possible for ruby users, that they can enable or disable a warning. 

 I found out that rails has this: 

     https://apidock.com/rails/Kernel/silence_warnings 

 I do not use rails myself, but I think I may not be the only one who thinks 
 that it may be more elegant to have a method. 

 I don't really care that much where this method will reside, be it in 
 Kernel, or in Warnings, or what particular name it has (although silence_warnings 
 is not a bad name). I think the more important question is whether matz feels 
 that the use case for being able to briefly silence a particular warning is 
 ok to have and worth a code addition/change, or not. 

 The above way to re-assign $VERBOSE works fine. It should be kept. At the same 
 time, though, looking at $variables is not that elegant, and it feels a tiny 
 bit hackish too; plus, it may be useful if ruby users may use a more common 
 idiom for this procedure. 

 I found out Note that rails has this: 

     https://apidock.com/rails/Kernel/silence_warnings 

 It may be elegant to have a method, be it in Kernel, or in Warnings, or another particular name (silence_warnings is not proposed primarily that we can modify a bad name). 

 constant, or a method. 
 There may be more use cases, cases for being able to disable warnings briefly, but 
 right now I am only thinking about these two use cases. 

 Do note that I refer ONLY to situations where the ruby developer would be aware at hand KNOWS that 
 he/she wants to silence a warning would be silenced. specifically. (Personally I run with -w all the 
 time, but not every warning is equally useful to me. me.) 

 It may be helpful if you could comment If you, as a ruby developer, have had a use case for something like this. It this in the 
 past, it may be also helpful if you could comment; and either way, it may be  
 helpful if others comment too, to state whether the use case may be useful 
 or not. 

 We not, so that the ruby core team gets a broader view as to how important 
 that would be (or how much used it could be; I think we can only settle for 
 a single short method. Otherwise, method though, and it should be short, because otherwise the  
 current way would be better. better).

Back