From: "David A. Black" Date: 2008-10-02T20:13:06+09:00 Subject: Re: printf statement - "args" as an Array (or something...) --1926193751-151137971-1222946061=:22741 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-151137971-1222946061=:22741" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-151137971-1222946061=:22741 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Thu, 2 Oct 2008, F. Senault wrote: > Le 02 octobre =E0 11:58, John Pritchard-williams a =E9crit : > >> 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 =3D "%s -> %s\n" > =3D> "%s -> %s\n" >>> args =3D [ "first", "second" ] > =3D> ["first", "second"] >>> printf(txt, *args) > first -> second > =3D> nil > >>> txt =3D "%s -> %s -> %s\n" > =3D> "%s -> %s -> %s\n" >>> printf(txt, *[ args, "third" ].flatten) > first -> second -> third > =3D> nil And in 1.9 you can do: [*args, "third"] David --=20 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! --1926193751-151137971-1222946061=:22741-- --1926193751-151137971-1222946061=:22741--