S
scott_mccaskill
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|
options.number = n
end
end
opts.parse!(args)[0]
options
end
options = parseArgs(ARGV)
p options
-----------------------------
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
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|
options.number = n
end
end
opts.parse!(args)[0]
options
end
options = parseArgs(ARGV)
p options
-----------------------------
<OpenStruct number=nil>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