best way to assign args ???

Discussion in 'Ruby' started by Une bévue, Aug 3, 2006.

  1. Une bévue

    Une bévue Guest

    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
    Une bévue, Aug 3, 2006
    #1
    1. Advertising

  2. 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 ???
    Morton Goldberg, Aug 3, 2006
    #2
    1. Advertising

  3. Une bévue

    Une bévue Guest

    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
    Une bévue, Aug 3, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    2
    Views:
    612
    Ken Varn
    Jun 22, 2005
  2. Replies:
    3
    Views:
    481
    David Eppstein
    Sep 17, 2003
  3. Pierre Fortin

    args v. *args passed to: os.path.join()

    Pierre Fortin, Sep 18, 2004, in forum: Python
    Replies:
    2
    Views:
    667
    Pierre Fortin
    Sep 18, 2004
  4. er
    Replies:
    2
    Views:
    485
  5. Andrew Tomazos
    Replies:
    5
    Views:
    560
Loading...

Share This Page