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.
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_option(opt, eq) ⇒ Object
Constructor Details
#initialize(*args) ⇒ ParseError
Returns a new instance of ParseError.
1593 1594 1595 1596 |
# File 'lib/optparse.rb', line 1593 def initialize(*args) @args = args @reason = nil end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
1598 1599 1600 |
# File 'lib/optparse.rb', line 1598 def args @args end |
#reason ⇒ Object
Returns error reason. Override this for I18N.
1621 1622 1623 |
# File 'lib/optparse.rb', line 1621 def reason @reason || self.class::Reason end |
Instance Method Details
#inspect ⇒ Object
1625 1626 1627 |
# File 'lib/optparse.rb', line 1625 def inspect "#<#{self.class.to_s}: #{args.join(' ')}>" end |
#message ⇒ Object Also known as: to_s
Default stringizing method to emit standard error message.
1632 1633 1634 |
# File 'lib/optparse.rb', line 1632 def reason + ': ' + args.join(' ') end |
#recover(argv) ⇒ Object
Pushes back erred argument(s) to argv.
1604 1605 1606 1607 |
# File 'lib/optparse.rb', line 1604 def recover(argv) argv[0, 0] = @args argv end |
#set_option(opt, eq) ⇒ Object
1609 1610 1611 1612 1613 1614 1615 1616 |
# File 'lib/optparse.rb', line 1609 def set_option(opt, eq) if eq @args[0] = opt else @args.unshift(opt) end self end |