def meth *argv
pa =
parseargs(argv) do
req_arg 'foo', 'bar'
opt_arg 'request' => 'useless'
opt_kw 'side'
opt_kw 'meat' => 'fish'
end
I idea is good but may I suggest it be a little less "cryptic"?
Something more like:
def meth *parm
parm = Parameters.new(parm) do
args :foo, :bar, :request => 'useless'
keys :side => nil, :meat => 'fish'
end
parm.foo
...
how do you say that an argument is optional then? are all keywords implied as
optional? why should it be so? parseargs handles both cases. by allowing
required_arguments
optional_arguments
required_keywords
optional_keywords
and shortcuts such as
req_arg, ra
req_kw, kw
of course you can say
arguments
keywords
all of the above (and there are more) takes lists. and these are by default
required. eg
def meth *argv
pa = parseargs argv do
arguments %w( foo bar )
keywords %w( foobar barfoo )
end
...
end
the reason i do not allow
arguments 'foo', 'bar' => 42
but do allow
argument 'foo' => 42
is that the options can be used to convey much more that a default value in
parseargs. it can be used to specify type, ducktype, coersion, default procs
instead of value only, etc. for example
arguments 'foo', 'bar', 'default' => 42, 'type' => Fixunm, 'ducktype' => 'to_i'
argument 'n', 'types' => [Fixunm, Float]
argument 'n', 'coerce' => :to_i
argument 'n', 'coerce' => lambda{|n| Integer n}
argument 's', 'ducktype' => %w( upcase downcase gsub )
so, basically, if you pass a __single__ argument that's a hash as in
argument 'foo' => 42
i know 42 is the default value for foo. if you pass more than one argument as
in
argument 'foo', 'bar', 'default' => '42', 'corece' => 'to_s'
i can't tell if the last hash is full of paramter names and default values or
metadata like type info and coercsion info. sure - it's obvious to the eye,
but makeing any assumptions would disallow this
argument 'default' => 42
here default is a parameter with a default value of 42. sticky.
you can read all about it here
http://codeforpeople.com/lib/ruby/parseargs/parseargs-0.3.0/README
You could also to set parm automatically, and of course a #parameters
constructor method is fine if you prefer, producing:
def meth *parm
parameters(parm) do
args :foo, :bar, :request => 'useless'
keys :side => nil, :meat => 'fish'
end
parm.foo
but that cannot be done? you cannot munge 'parm' in place and set it to
another variable? perhaps i'm not understanding?
cheers.
-a
···
On Tue, 25 Oct 2005, Trans wrote:
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
anything that contradicts experience and logic should be abandoned.
-- h.h. the 14th dalai lama
===============================================================================