From: "Ara.T.Howard" Date: 2005-10-24T13:12:01+09:00 Subject: Re: A comparison by example of keyword argument styles On Mon, 24 Oct 2005, Trans wrote: > That's nice, but then why would we need key args if we'd do this anyway? that was my point ;-) just wondering out loud how important lanuage support greater than collecting open key/values pairs is... >> From what I understand this isn't what will happen, but rather > >> meth 42, foo : 42 #=> [ [42, {:foo => 42}], {:foo => 42} ] eek! >> meth 42, 'foo' => 42, foo : 42 #=> Error eeeeek! >> i might add that i hope whatever keys object will hash key and symbol >> arguments the same so we can do >> >> val = keys['foo'] >> or >> >> val = keys[:foo] >> >> i hate having to check for both (that's what getopt above does). > > Interesting point. Perhaps better then: > > val = keys.foo i do like verbose = keys.value_at(%w( verbose verbosity v )).first eg - a hash interface. > Would go even better with Evan's mixed parameter object. > > def(*parms) > p parms > p parms.named > p parms.foo > end > > foo( 1,2,foo:3 ) > => [1,2] > {:foo=>3} > 3 harp:~ > cat a.rb require 'parseargs' include ParseArgs def meth *argv pa = parseargs(argv){ args %w( a b ) and kws %w( c d ) } p pa.arguments.map{|a| a.name} p pa.keywords.map{|k| k.name} p pa.a p pa.b p pa.c p pa.d end meth 4, 2, 'c' => 'forty', 'd' => 'two' harp:~ > ruby a.rb ["a", "b"] ["c", "d"] 4 2 "forty" "two" ;-) -a -- =============================================================================== | 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 ===============================================================================