| Module | StructuredWarnings::Warning |
| In: |
lib/structured_warnings/warning.rb
|
This module encapsulates the extensions to Warning, that are introduced by this library.
This method provides a raise-like interface. It extends the default warn in ::Warning to allow the use of structured warnings.
Internally it uses the StructuredWarnings::warner to format a message based on the given warning class, the message and a stack frame. The return value is passed to super, which is likely the implementation in ::Warning. That way, it is less likely, that structured_warnings interferes with other extensions.
If the warner returns nil or an empty string the underlying warn will not be called. That way, warnings may be transferred to other devices without the need to redefine ::Warning#warn.
Just like the original version, this method does not take command line switches or verbosity levels into account. In order to deactivate all warnings use StructuredWarnings::Base.disable.
warn "This is an old-style warning" # This will emit a StructuredWarnings::StandardWarning
class Foo
def bar
warn StructuredWarnings::DeprecationWarning, "Never use bar again, use beer"
end
def beer
"Ahhh"
end
end
warn StructuredWarnings::Base.new("The least specific warning you can get")