best way to assign args ???

U

Une bévue

on Mac OS X using launchd i'm only able to pass args like that :

["DEBUGG=true", "auto=true", "dummy=empty",
"files=/Users/yvon/MacSOUP_proxad/proxad,
/Users/yvon/MacSOUP_eclipse/eclipse,
/Users/yvon/MacSOUP_news.individual.net/individual"]


then for the time being i do :

@h={}
$*.each {|a| k,v=a.split("="); @h[k]=v}

and, afterwards :

@h['DEBUGG']=(@h['DEBUGG']=="true")
for bool, and for array :

@h['files']=@h['files'].split(", ")

i don't like that because i have to know, a priori, the types and names
of the args.

a better solution more rubyish ???
 
M

Morton Goldberg

The following does what you want in one pass:

INP =3D ["DEBUGG=3Dtrue", "auto=3Dtrue", "dummy=3Dempty",
"files=3D/Users/yvon/MacSOUP_proxad/proxad, /Users/yvon/MacSOUP_eclipse/=20=

eclipse, /Users/yvon/MacSOUP_news.individual.net/individual"]

@h =3D {}
INP.each do |a|
k,v =3D a.split("=3D")
case v
when /true/ then @h[k] =3D true
when /false/ then @h[k] =3D false
when /,[\s]*/ then @h[k] =3D v.split(/,[\s]*/)
else @h[k] =3D v
end
end

It is easily extend to other cases if necessary. Whether or not it is =20=

better or more Ruby-ish is for you to decide.

Hope this helps.

Regards, Morton
 
U

Une bévue

Morton Goldberg said:
The following does what you want in one pass:

fanstatic !
[snip]

It is easily extend to other cases if necessary. Whether or not it is
better or more Ruby-ish is for you to decide.

Hope this helps.

yes it helps me having different solutions, at least.

thanx

Yvon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top