Issue #9423 has been updated by Atlas Prime.


That's a great idea! Abstracting the interface away as a method leaves the underpinnings free for adjustment. With that, it seems most intuitive that `-W[level]` would simply translate directly into $WARN=level. And `-W0` flag would still mean "no warnings".

I worked on making an exact definition `#warning?`. It soon become clear to me that it was more complicated than it seemed it should be b/c what it was really calling for two methods, not just one. With two methods it becomes very simple. What do you think of:

    # medium warnings
    if notice?
      $WARN >= 1
    end

    # strong warnings
    if warning?(level=2)
      $WARN >= level
    end

That way we can use `if` and `unless` on either `notice?` or `warning?` and not have to worry about the level at all (except for supporting rare high levels >= 3).


----------------------------------------
Feature #9423: Improve warning semantics
https://bugs.ruby-lang.org/issues/9423#change-44420

* Author: Atlas Prime
* Status: Feedback
* Priority: Normal
* Assignee: 
* Category: core
* Target version: current: 2.2.0
----------------------------------------
Two suggestions for future version of Ruby that wold make warning levels more intuitive easier to work with.

First, rename $VERBOSE to $WARN for these reasons:

* `ruby` flags that set $VERBOSE are `-w` and `-W` (warnings levels).
* $VERBOSE controls output produced by `warn` method.
* $VERBOSE and FileUtils:Verbose are unrelated.
* $WARN is shorter ;-)

Second, it is confusing that `nil` and `false` mean different levels. Instead of the current `nil` as level 0, `false` as level 1, and `true` as level 2, it would be nice if `nil` and `false` both mean "off", and then go from 0 on up to mean "on" of increasing degree. Just to clarify my meaning (not a use case example):

    # nil, false mean no warning
    if $WARN
      case $WARN
      when 0
        # lesser level of warning
      when 1
        # greater level of warning
      when 2
        # can go higher if needed for rare use case
      end
    end

These are incompatible changes, but can be phased-in with support both $WARN and $VERBOSE for intermediate period.




-- 
http://bugs.ruby-lang.org/