Exception: Gem::OptionParser::ParseError
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- Gem::OptionParser::ParseError
- Defined in:
- lib/rubygems/optparse/lib/optparse.rb
Overview
Base class of exceptions from Gem::OptionParser.
Direct Known Subclasses
AmbiguousOption, InvalidArgument, InvalidOption, MissingArgument, NeedlessArgument
Constant Summary collapse
- Reason =
Reason which caused the error.
'parse error'
Instance Attribute Summary collapse
-
#additional ⇒ Object
Returns the value of attribute additional.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#reason ⇒ Object
Returns error reason.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args, additional: nil) ⇒ 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, additional: nil) ⇒ ParseError
Returns a new instance of ParseError.
2099 2100 2101 2102 2103 2104 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2099 def initialize(*args, additional: nil) @additional = additional @arg0, = args @args = args @reason = nil end |
Instance Attribute Details
#additional ⇒ Object
Returns the value of attribute additional.
2108 2109 2110 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2108 def additional @additional end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
2106 2107 2108 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2106 def args @args end |
#reason ⇒ Object
Returns error reason. Override this for I18N.
2141 2142 2143 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2141 def reason @reason || self.class::Reason end |
Class Method Details
.filter_backtrace(array) ⇒ Object
2118 2119 2120 2121 2122 2123 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2118 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
2145 2146 2147 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2145 def inspect "#<#{self.class}: #{args.join(' ')}>" end |
#message ⇒ Object Also known as: to_s
Default stringizing method to emit standard error message.
2152 2153 2154 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2152 def "#{reason}: #{args.join(' ')}#{additional[@arg0] if additional}" end |
#recover(argv) ⇒ Object
Pushes back erred argument(s) to argv
.
2113 2114 2115 2116 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2113 def recover(argv) argv[0, 0] = @args argv end |
#set_backtrace(array) ⇒ Object
2125 2126 2127 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2125 def set_backtrace(array) super(self.class.filter_backtrace(array)) end |
#set_option(opt, eq) ⇒ Object
2129 2130 2131 2132 2133 2134 2135 2136 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2129 def set_option(opt, eq) if eq @args[0] = opt else @args.unshift(opt) end self end |