Index: lib/optparse.rb =================================================================== --- lib/optparse.rb (revision 42822) +++ lib/optparse.rb (working copy) @@ -1637,8 +1637,9 @@ XXX decimal = '\d+(?:_\d+)*' binary = 'b[01]+(?:_[01]+)*' hex = 'x[\da-f]+(?:_[\da-f]+)*' - octal = "0(?:[0-7]*(?:_[0-7]+)*|#{binary}|#{hex})" + octal = "0(?:[0-7]+(?:_[0-7]+)*|#{binary}|#{hex})?" integer = "#{octal}|#{decimal}" + accept(Integer, %r"\A[-+]?(?:#{integer})"io) {|s,| Integer(s) if s} # @@ -1664,22 +1665,34 @@ XXX # # Decimal integer format, to be converted to Integer. # - DecimalInteger = /\A[-+]?#{decimal}/io - accept(DecimalInteger) {|s,| s.to_i if s} + DecimalInteger = /\A([-+]?#{decimal})/io + accept(DecimalInteger, DecimalInteger) {|s,d| + begin + Integer(d) + rescue ArgumentError + raise OptionParser::InvalidArgument, s + end + } # # Ruby/C like octal/hexadecimal/binary integer format, to be converted to # Integer. # OctalInteger = /\A[-+]?(?:[0-7]+(?:_[0-7]+)*|0(?:#{binary}|#{hex}))/io - accept(OctalInteger) {|s,| s.oct if s} + accept(OctalInteger, OctalInteger) {|s,| s.oct if s} # # Decimal integer/float number format, to be converted to Integer for # integer format, Float for float format. # DecimalNumeric = floatpat # decimal integer is allowed as float also. - accept(DecimalNumeric) {|s,| eval(s) if s} + accept(DecimalNumeric, floatpat) {|s,| + begin + eval(s) + rescue SyntaxError + raise OptionParser::InvalidArgument, s + end if s + } # # Boolean switch, which means whether it is present or not, whether it is