From: Timothy Hunter Date: 2006-12-28T05:41:49+09:00 Subject: Re: Handling of arbitrary length arrays in arguments to printf builtin Jason Mayer wrote: > On 12/27/06, Timothy Hunter wrote: >> >> Welcoingme to Ruby! >> >> Use the "*" (splat) operator to turn the array into a list of arguments. >> >> printf "%s %s", *@params >> >> The unary asterisk is often called the "unary unarray" operator because >> it has this effect on an array. > > > Neat! How would you use that to return "bar stuff" with the following? > > @params = ["foo", "bar", "stuff"] > print @params.inspect > printf "%s %s", *@params You can't. That's not what "*" is for. The "unary unarray" operator is primarily used for exactly the purpose you described, variable-length argument lists. It has uses in other contexts, too, but they're outside the scope of your question. If you want just some of the elements in the Array then you can use the [] method and specify which elements you're interested in. In your example, @params[1,2] ("2 elements starting at element 1") would do the trick. > > I'm not sure that Ri Array#* is quite what I meant to look for. You're right. In this context "*" is a unary operator. Array#* is a method.