From: shevegen@... Date: 2020-03-19T20:54:40+00:00 Subject: [ruby-core:97557] [Ruby master Feature#16699] Consider providing ruby developers with a way to specifically silence/ignore particular warnings from some parts of the code (in a .rb file) Issue #16699 has been reported by shevegen (Robert A. Heiler). ---------------------------------------- Feature #16699: Consider providing ruby developers with a way to specifically silence/ignore particular warnings from some parts of the code (in a .rb file) https://bugs.ruby-lang.org/issues/16699 * Author: shevegen (Robert A. Heiler) * Status: Open * Priority: Normal ---------------------------------------- In ruby it is possible to silence a specific 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 for re-defining a method. I had to add an instance variable to that method. There are alternatives, e. g. including a module, or subclassing, but I actually really wanted to just re-define the method as-is, without incurring a warning message on the 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. Note that it is proposed primarily that we can modify a constant, or a method. There may be more use 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 at hand KNOWS that he/she wants to silence a warning specifically. (Personally I run with -w all the time, but not every warning is equally useful to me.) If you, as a ruby developer, have had a use case for something like this in the past, it may be 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, 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 method though, and it should be short, because otherwise the current way would be better). -- https://bugs.ruby-lang.org/ Unsubscribe: