Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > best way to assign args ???

Reply
Thread Tools

best way to assign args ???

 
 
Une bévue
Guest
Posts: n/a
 
      08-03-2006
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 ???
--
une bévue
 
Reply With Quote
 
 
 
 
Morton Goldberg
Guest
Posts: n/a
 
      08-03-2006
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

On Aug 3, 2006, at 6:35 AM, Une b=E9vue wrote:

> on Mac OS X using launchd i'm only able to pass args like that :
>
> ["DEBUGG=3Dtrue", "auto=3Dtrue", "dummy=3Dempty",
> "files=3D/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=3D{}
> $*.each {|a| k,v=3Da.split("=3D"); @h[k]=3Dv}
>
> and, afterwards :
>
> @h['DEBUGG']=3D(@h['DEBUGG']=3D=3D"true")
> for bool, and for array :
>
> @h['files']=3D@h['files'].split(", ")
>
> i don't like that because i have to know, a priori, the types and =20
> names
> of the args.
>
> a better solution more rubyish ???


 
Reply With Quote
 
 
 
 
Une bévue
Guest
Posts: n/a
 
      08-03-2006
Morton Goldberg <> wrote:

> 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
--
une bévue
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
forwarding Args&&... vs forwarding Args... Andrew Tomazos C++ 5 01-05-2012 11:15 PM
C++0x -- fun(Args&...) and fun(Args const&...) er C++ 2 12-20-2010 07:52 PM
Is there a class or method to construct url args or extract url args? Ken Varn ASP .Net 2 06-22-2005 12:26 PM
args v. *args passed to: os.path.join() Pierre Fortin Python 2 09-18-2004 06:59 PM
When passing functions as args,how to pass extra args for passed function? python@sarcastic-horse.com Python 3 09-17-2003 12:25 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57