module StructuredWarnings::Base::ClassMethods
This module extends StructuredWarnings::Base
and each subclass. It may be used to activate or deactivate a set of warnings.
Public Instance Methods
Source
# File lib/structured_warnings/base.rb, line 54 def active? StructuredWarnings::disabled_warnings.all? {|w| !(w >= self)} end
returns a Boolean, stating whether a warning of this type would be emmitted or not.
Source
# File lib/structured_warnings/base.rb, line 83 def disable if block_given? StructuredWarnings::with_disabled_warnings(StructuredWarnings.disabled_warnings | [self]) do yield end else StructuredWarnings::disabled_warnings |= [self] end end
If called without a block, warnings of this type will be disabled in the current thread and all new child threads.
warn("this will be printed") # creates a StructuredWarnings::StandardWarning # which is enabled by default StructuredWarnings::Base.disable warn("this will not be printed") # creates a StructuredWarnings::StandardWarning # which is currently disabled
If called with a block, warnings of this type will be disabled in the dynamic scope of the given block.
StructuredWarnings::Base.disable do warn("this will not be printed") # creates a StructuredWarnings::StandardWarning # which is currently disabled end warn("this will be printed") # creates a StructuredWarnings::StandardWarning # which is currently enabled
Source
# File lib/structured_warnings/base.rb, line 100 def enable if block_given? StructuredWarnings::with_disabled_warnings(StructuredWarnings.disabled_warnings - [self]) do yield end else StructuredWarnings::disabled_warnings -= [self] end end
This method has the same semantics as disable, only with the opposite outcome. In general the last assignment wins, so that disabled warnings may be enabled again and so on.