Re: what does *my_array do?



Hi --

On Sat, 1 Oct 2005, Shea Martin wrote:

using tk in ruby, when I add my_array to a listbox it adds all the items as a single large string. when I add them as *my_array it puts them in correctly.

I got *my_array from a example on web, but I don't know what it means.

It "un-arrays" the array, turning it back into a plain list of objects. For example:

  a = [3,4,5]
  b = [1,2,*a]  # [1,2,3,4,5]

as opposed to:

  b = [1,2,a]   # [1,2,[3,4,5]]

It also plays a role in method calls.  This:

  def x(*args)

is a method that can take any number of arguments (including zero),
and will store them in the array args.


David

--
David A. Black
dblack@xxxxxxxxxxxx


.