Exception: OptionParser::ParseError
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- OptionParser::ParseError
- Defined in:
- lib/optparse.rb
Overview
Base class of exceptions from OptionParser.
Direct Known Subclasses
AmbiguousOption, InvalidArgument, InvalidOption, MissingArgument, NeedlessArgument
Constant Summary collapse
- Reason =
Reason which caused the error.
'parse error'.freeze
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#reason ⇒ Object
Returns error reason.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ ParseError
constructor
A new instance of ParseError.
- #inspect ⇒ Object
-
#message ⇒ Object
(also: #to_s)
Default stringizing method to emit standard error message.
-
#recover(argv) ⇒ Object
Pushes back erred argument(s) to
argv
. - #set_backtrace(array) ⇒ Object
- #set_option(opt, eq) ⇒ Object
Constructor Details
#initialize(*args) ⇒ ParseError
Returns a new instance of ParseError.
1735 1736 1737 1738 |
# File 'lib/optparse.rb', line 1735 def initialize(*args) @args = args @reason = nil end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args
1740 1741 1742 |
# File 'lib/optparse.rb', line 1740 def args @args end |
#reason ⇒ Object
Returns error reason. Override this for I18N.
1774 1775 1776 |
# File 'lib/optparse.rb', line 1774 def reason @reason || self.class::Reason end |
Class Method Details
.filter_backtrace(array) ⇒ Object
1751 1752 1753 1754 1755 1756 |
# File 'lib/optparse.rb', line 1751 def self.filter_backtrace(array) unless $DEBUG array.delete_if(&%r"\A#{Regexp.quote(__FILE__)}:"o.method(:=~)) end array end |
Instance Method Details
#inspect ⇒ Object
1778 1779 1780 |
# File 'lib/optparse.rb', line 1778 def inspect "#<#{self.class.to_s}: #{args.join(' ')}>" end |
#message ⇒ Object Also known as: to_s
Default stringizing method to emit standard error message.
1785 1786 1787 |
# File 'lib/optparse.rb', line 1785 def reason + ': ' + args.join(' ') end |
#recover(argv) ⇒ Object
Pushes back erred argument(s) to argv
.
1746 1747 1748 1749 |
# File 'lib/optparse.rb', line 1746 def recover(argv) argv[0, 0] = @args argv end |
#set_backtrace(array) ⇒ Object
1758 1759 1760 |
# File 'lib/optparse.rb', line 1758 def set_backtrace(array) super(self.class.filter_backtrace(array)) end |
#set_option(opt, eq) ⇒ Object
1762 1763 1764 1765 1766 1767 1768 1769 |
# File 'lib/optparse.rb', line 1762 def set_option(opt, eq) if eq @args[0] = opt else @args.unshift(opt) end self end |