Class: StructuredWarnings::Base
- Inherits:
-
Object
- Object
- StructuredWarnings::Base
- Extended by:
- ClassMethods
- Defined in:
- lib/structured_warnings/base.rb
Overview
Descendents of class StructuredWarnings::Base are used to raise structured warnings. They enable programmers to explicitly supress certain kinds of warnings and provide additional information in contrast to the plain warn method. They implement an Exception-like interface and carry information about the warning -- its type (the warning's class name), an optional descriptive string, and optional traceback information. Programs may subclass StructuredWarnings::Base to add additional information.
Large portions of this class's documentation are taken from the Exception RDoc.
Direct Known Subclasses
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#backtrace ⇒ Object
call-seq: warning.backtrace => array.
-
#initialize(message = nil) ⇒ Base
constructor
Construct a new StructuredWarning::Base object, optionally passing in a message.
-
#inspect ⇒ Object
Return this warning's class name and message.
-
#set_backtrace(backtrace) ⇒ Object
Sets the backtrace information associated with warning.
-
#to_s ⇒ Object
(also: #to_str, #message)
Returns warning's message (or the name of the warning if no message is set).
Methods included from ClassMethods
Constructor Details
#initialize(message = nil) ⇒ Base
Construct a new StructuredWarning::Base object, optionally passing in a message.
14 15 16 17 |
# File 'lib/structured_warnings/base.rb', line 14 def initialize( = nil) @message = @backtrace = caller(1) end |
Instance Method Details
#backtrace ⇒ Object
call-seq:
warning.backtrace => array
Returns any backtrace associated with the warning. The backtrace
is an array of strings, each containing either filename:lineNo: in `method''' or filename:lineNo.''
26 27 28 |
# File 'lib/structured_warnings/base.rb', line 26 def backtrace @backtrace end |
#inspect ⇒ Object
Return this warning's class name and message
45 46 47 |
# File 'lib/structured_warnings/base.rb', line 45 def inspect "#<#{self.class}: #{self}>" end |
#set_backtrace(backtrace) ⇒ Object
Sets the backtrace information associated with warning. The argument must be an array of String objects in the format described in Exception#backtrace.
33 34 35 |
# File 'lib/structured_warnings/base.rb', line 33 def set_backtrace(backtrace) @backtrace = backtrace end |
#to_s ⇒ Object Also known as: to_str, message
Returns warning's message (or the name of the warning if no message is set).
38 39 40 |
# File 'lib/structured_warnings/base.rb', line 38 def to_s @message || self.class.name end |