From: Assaph Mehr Date: 2005-02-02T08:10:43+09:00 Subject: Re: optparse problem scott_mccask...@yahoo.com wrote: > >From looking at the optparse example in optparse.rb, it seems like the > following should work, but it doesn't: > > ----------------------------- > > require 'optparse' > require 'ostruct' > > def parseArgs(args) > options = OpenStruct.new > options.number = 1 > > opts = OptionParser.new do |opts| > opts.on("--number", Integer, "an integer") do |n| opts.on("--number INTEGER", Integer, "an integer") do |n| you need to tell optparse that there is a mandatoty parameter for the option. > options.number = n > end > end > > opts.parse!(args)[0] > options > end > > options = parseArgs(ARGV) > p options > > ----------------------------- > > > ruby opts.rb --number 42 > > > It works for Float (as in the example in optparse.rb), but not for > Integer; is this intentional? Using ruby 1.8.2 (2004-12-25) > [i386-mswin32] > > Thanks, > Scott