Exception: OptionParser::ParseError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/optparse.rb

Overview

Base class of exceptions from OptionParser.

Constant Summary collapse

Reason =

Reason which caused the error.

'parse error'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argsObject (readonly)

Returns the value of attribute args.



1596
1597
1598
# File 'lib/optparse.rb', line 1596

def args
  @args
end

#reasonObject

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

#inspectObject



1623
1624
1625
# File 'lib/optparse.rb', line 1623

def inspect
  "#<#{self.class.to_s}: #{args.join(' ')}>"
end

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.



1630
1631
1632
# File 'lib/optparse.rb', line 1630

def message
  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