class StructuredWarnings::Base

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.

Public Class Methods

new(message = nil) click to toggle source

Construct a new StructuredWarning::Base object, optionally passing in a message.

# File lib/structured_warnings/base.rb, line 14
def initialize(message = nil)
  @message = message
  @backtrace = caller(1)
end

Public Instance Methods

backtrace → array click to toggle source

Returns any backtrace associated with the warning. The backtrace is an array of strings, each containing either “filename:lineNo: in ‘method”’ or “filename:lineNo.”

# File lib/structured_warnings/base.rb, line 26
def backtrace
  @backtrace
end
inspect() click to toggle source

Return this warning’s class name and message

# File lib/structured_warnings/base.rb, line 45
def inspect
  "#<#{self.class}: #{self}>"
end
message()
Alias for: to_s
set_backtrace(backtrace) click to toggle source

Sets the backtrace information associated with warning. The argument must be an array of String objects in the format described in Exception#backtrace.

# File lib/structured_warnings/base.rb, line 33
def set_backtrace(backtrace)
  @backtrace = backtrace
end
to_s() click to toggle source

Returns warning’s message (or the name of the warning if no message is set).

# File lib/structured_warnings/base.rb, line 38
def to_s
  @message || self.class.name
end
Also aliased as: to_str, message
to_str()
Alias for: to_s