Trouble is I need a variable list as the args: I can't seem to pass in :
["one","two"] - is there an idiom for this ?
Splat it.
txt = "%s -> %s\n"
=> "%s -> %s\n"
args = [ "first", "second" ]
=> ["first", "second"]
printf(txt, *args)
first -> second
=> nil
txt = "%s -> %s -> %s\n"
=> "%s -> %s -> %s\n"
printf(txt, *[ args, "third" ].flatten)
first -> second -> third
=> nil
Fred
···
Le 02 octobre à 11:58, John Pritchard-williams a écrit :
--
I was broken, bent out of shape I was naked in the clothes you made
Lips were dry, throat like rust You gave me shelter
From the heat and the dust There's no more water in the well
No more water in the well (U2, Trip Through Your Wires)
Le 02 octobre à 11:58, John Pritchard-williams a écrit :
Trouble is I need a variable list as the args: I can't seem to pass in :
["one","two"] - is there an idiom for this ?
Splat it.
txt = "%s -> %s\n"
=> "%s -> %s\n"
args = [ "first", "second" ]
=> ["first", "second"]
printf(txt, *args)
first -> second
=> nil
txt = "%s -> %s -> %s\n"
=> "%s -> %s -> %s\n"
printf(txt, *[ args, "third" ].flatten)
first -> second -> third
=> nil
And in 1.9 you can do:
[*args, "third"]
David
--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!