W3cubDocs

/Ruby 3

class OptionParser::ParseError

Parent:
RuntimeError

Base class of exceptions from OptionParser.

Constants

Reason

Reason which caused the error.

Attributes

additional[RW]
args[R]
reason[W]

Public Class Methods

filter_backtrace(array) Show source
# File lib/optparse.rb, line 2049
def self.filter_backtrace(array)
  unless $DEBUG
    array.delete_if(&%r"\A#{Regexp.quote(__FILE__)}:"o.method(:=~))
  end
  array
end
new(*args, additional: nil) Show source
# File lib/optparse.rb, line 2030
def initialize(*args, additional: nil)
  @additional = additional
  @arg0, = args
  @args = args
  @reason = nil
end

Public Instance Methods

inspect() Show source
# File lib/optparse.rb, line 2076
def inspect
  "#<#{self.class}: #{args.join(' ')}>"
end
message() Show source
# File lib/optparse.rb, line 2083
def message
  "#{reason}: #{args.join(' ')}#{additional[@arg0] if additional}"
end

Default stringizing method to emit standard error message.

Also aliased as: to_s
reason() Show source
# File lib/optparse.rb, line 2072
def reason
  @reason || self.class::Reason
end

Returns error reason. Override this for I18N.

recover(argv) Show source
# File lib/optparse.rb, line 2044
def recover(argv)
  argv[0, 0] = @args
  argv
end

Pushes back erred argument(s) to argv.

set_backtrace(array) Show source
# File lib/optparse.rb, line 2056
def set_backtrace(array)
  super(self.class.filter_backtrace(array))
end
Calls superclass method Exception#set_backtrace
set_option(opt, eq) Show source
# File lib/optparse.rb, line 2060
def set_option(opt, eq)
  if eq
    @args[0] = opt
  else
    @args.unshift(opt)
  end
  self
end
to_s()
Alias for: message

Ruby Core © 1993–2020 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.