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.
2026 2027 2028 2029 2030 2031 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2026 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.
2035 2036 2037 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2035 def additional @additional end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
2033 2034 2035 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2033 def args @args end |
#reason ⇒ Object
Returns error reason. Override this for I18N.
2068 2069 2070 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2068 def reason @reason || self.class::Reason end |
Class Method Details
.filter_backtrace(array) ⇒ Object
2045 2046 2047 2048 2049 2050 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2045 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
2072 2073 2074 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2072 def inspect "#<#{self.class}: #{args.join(' ')}>" end |
#message ⇒ Object Also known as: to_s
Default stringizing method to emit standard error message.
2079 2080 2081 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2079 def "#{reason}: #{args.join(' ')}#{additional[@arg0] if additional}" end |
#recover(argv) ⇒ Object
Pushes back erred argument(s) to argv
.
2040 2041 2042 2043 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2040 def recover(argv) argv[0, 0] = @args argv end |
#set_backtrace(array) ⇒ Object
2052 2053 2054 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2052 def set_backtrace(array) super(self.class.filter_backtrace(array)) end |
#set_option(opt, eq) ⇒ Object
2056 2057 2058 2059 2060 2061 2062 2063 |
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2056 def set_option(opt, eq) if eq @args[0] = opt else @args.unshift(opt) end self end |