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.
1794 1795 1796 1797 |
# File 'lib/optparse.rb', line 1794 def initialize(*args) @args = args @reason = nil end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args
1799 1800 1801 |
# File 'lib/optparse.rb', line 1799 def args @args end |
#reason ⇒ Object
Returns error reason. Override this for I18N.
1833 1834 1835 |
# File 'lib/optparse.rb', line 1833 def reason @reason || self.class::Reason end |
Class Method Details
.filter_backtrace(array) ⇒ Object
1810 1811 1812 1813 1814 1815 |
# File 'lib/optparse.rb', line 1810 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
1837 1838 1839 |
# File 'lib/optparse.rb', line 1837 def inspect "#<#{self.class}: #{args.join(' ')}>" end |
#message ⇒ Object Also known as: to_s
Default stringizing method to emit standard error message.
1844 1845 1846 |
# File 'lib/optparse.rb', line 1844 def reason + ': ' + args.join(' ') end |
#recover(argv) ⇒ Object
Pushes back erred argument(s) to argv
.
1805 1806 1807 1808 |
# File 'lib/optparse.rb', line 1805 def recover(argv) argv[0, 0] = @args argv end |
#set_backtrace(array) ⇒ Object
1817 1818 1819 |
# File 'lib/optparse.rb', line 1817 def set_backtrace(array) super(self.class.filter_backtrace(array)) end |
#set_option(opt, eq) ⇒ Object
1821 1822 1823 1824 1825 1826 1827 1828 |
# File 'lib/optparse.rb', line 1821 def set_option(opt, eq) if eq @args[0] = opt else @args.unshift(opt) end self end |