From: Jim Freeze Date: 2005-09-14T00:37:39+09:00 Subject: Re: yet another simple command-line option parser That's pretty interesting Eric, to grab the type off the default. I think I'll add that to CommandLine::OptionParser. However, I'm still not sure if I like the #from_s form, but I can see the utility of it. For the common cases, I can use a simple case statement: case default when Float then Float(arg) when Fixnum then Integer(arg) end But, as you can see with even these simple cases, there are big issues and big questions to answer. 1. Fixnum does not match Integer 2. Do we use to_i or Integer(#) - Integer raises and to_i does not 3. Do we use Float or to_f - Float raises and to_f does not Then, there are the tougher cases like require 'parsedate' case default when Time then Time.gm(*ParseDate.parsedate(arg)) when Fixnum arg.to_i # what if yield bignum end where we have to use a help class and helper method (not new) to get the object we want. Or if the conversion method returns something other than what we requested, like Bignum instead of Fixnum. Sadly, the #from_s RCR doesn't seem to address any of these issues. > ARGV.replace(%w( > -n 4 > -multiplier 3.14 > -q > -title foobar > -pattern fo+ > -time 5:55PM > -method downcase > a b c > )) > # option => default (or false for a flag) > argv_options( > :n => 1, > :multiplier => 1.0, > :q => false, > :title => "hello world!", > :pattern => /.*/, > :time => Time.new, > :method => :to_s > ) -- Jim Freeze