Parent

Namespace

Files

Warning

Descendents of class Warning are used to raise structured warnings. They 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 Warning 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 Warning object, optionally passing in a message.

# File lib/structured_warnings/warning.rb, line 13
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/warning.rb, line 25
def backtrace
  @backtrace
end
inspect() click to toggle source

Return this warning’s class name and message

# File lib/structured_warnings/warning.rb, line 44
def inspect
  "#<#{self.class}: #{self}>"
end
message() click to toggle source
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/warning.rb, line 32
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/warning.rb, line 37
def to_s
  @message || self.class.name
end
Also aliased as: to_str, message
to_str() click to toggle source
Alias for: to_s

[Validate]

Generated with the Darkfish Rdoc Generator 2.