module Warning::ClassMethods
This module extends Warning and each subclass. It may be used to activate or deactivate a set of warnings.
Public Instance Methods
active?()
click to toggle source
returns a Boolean, stating whether a warning of this type would be emmitted or not.
# File lib/structured_warnings/warning.rb, line 53 def active? StructuredWarnings::disabled_warnings.all? {|w| !(w >= self)} end
disable()
click to toggle source
disable() {...}
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 StandardWarning which is # enabled by default Warning.disable warn("this will not be printed") # creates a 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.
Warning.disable do warn("this will not be printed") # creates a StandardWarning which is # currently disabled end warn("this will be printed") # creates a StandardWarning which is # currently enabled
# File lib/structured_warnings/warning.rb, line 82 def disable if block_given? StructuredWarnings::with_disabled_warnings( StructuredWarnings.disabled_warnings | [self]) do yield end else StructuredWarnings::disabled_warnings |= [self] end end
enable()
click to toggle source
enable() {...}
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.
# File lib/structured_warnings/warning.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