Assaph Mehr
2/1/2005 11:02:00 PM
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
> <OpenStruct number=nil>
>
> 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