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
1591 1592 1593 1594 |
# File 'lib/optparse.rb', line 1591 def initialize(*args) @args = args @reason = nil end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
1596 1597 1598 |
# File 'lib/optparse.rb', line 1596 def args @args end |
#reason ⇒ Object
Returns error reason. Override this for I18N.
1619 1620 1621 |
# File 'lib/optparse.rb', line 1619 def reason @reason || self.class::Reason end |
Instance Method Details
#inspect ⇒ Object
1623 1624 1625 |
# File 'lib/optparse.rb', line 1623 def inspect "#<#{self.class.to_s}: #{args.join(' ')}>" end |
#message ⇒ Object Also known as: to_s
Default stringizing method to emit standard error message.
1630 1631 1632 |
# File 'lib/optparse.rb', line 1630 def reason + ': ' + args.join(' ') end |
#recover(argv) ⇒ Object
Pushes back erred argument(s) to argv.
1602 1603 1604 1605 |
# File 'lib/optparse.rb', line 1602 def recover(argv) argv[0, 0] = @args argv end |
#set_option(opt, eq) ⇒ Object
1607 1608 1609 1610 1611 1612 1613 1614 |
# File 'lib/optparse.rb', line 1607 def set_option(opt, eq) if eq @args[0] = opt else @args.unshift(opt) end self end |