Project

General

Profile

Actions

Bug #7537

closed

OptionParser treats negative digits as options

Added by prijutme4ty (Ilya Vorontsov) over 11 years ago. Updated over 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
1.9.3(p0, p327 both)
Backport:
[ruby-core:50706]

Description

Is it intentional that negative digits are treated as options?
If I use negative digit as an argument of an option, it is treated as a number

OptionParser.new {|opts|
opts.on('-p','--pvalue VAL', Integer, 'P-value') {|v| puts "P-value: #{v}" }
}.parse!

ruby my_test.rb -p -1 works normally

But if I use it as optional argument of an option:

OptionParser.new {|opts|
opts.on('-p','--pvalue [VAL]', Integer, 'P-value') {|v| puts "P-value: #{v}" }
}.parse!

ruby my_test.rb -p -1 fails with "Invalid option -1"

Also I can't use it as non-optional argument

OptionParser.new {|opts|
opts.on('-n', 'no Pvalue argument, other arguments only') {}
}.parse!
puts ARGV

ruby my_test.rb -1 also fails with "Invalid option -1"


Files

259.patch (10.2 KB) 259.patch zzak (zzak _), 04/05/2013 11:38 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0