Array question

Hello,

I have a function like this:

def f(*args)
  #do something
end

and I have an array, say

a = [1,2,3]

Now I would like to call f() with the contents of the array i.e.

f(1,2,3) in this case (i.e. not f([1,2,3]) )

What is the most Rubyish way to accomplish this?

TIA,
Peter

···

--
http://www.rubyrailways.com

Splat the array first with the * (splat) operator.
f(*a)

···

On 11/10/06, Peter Szinek <peter@rubyrailways.com> wrote:

Hello,

I have a function like this:

def f(*args)
  #do something
end

and I have an array, say

a = [1,2,3]

Now I would like to call f() with the contents of the array i.e.

f(1,2,3) in this case (i.e. not f([1,2,3]) )

What is the most Rubyish way to accomplish this?

TIA,
Peter

--

f(*a)

Farrel

···

On 09/11/06, Peter Szinek <peter@rubyrailways.com> wrote:

Hello,

I have a function like this:

def f(*args)
  #do something
end

and I have an array, say

a = [1,2,3]

Now I would like to call f() with the contents of the array i.e.

f(1,2,3) in this case (i.e. not f([1,2,3]) )

What is the most Rubyish way to accomplish this?

TIA,
Peter

--
http://www.rubyrailways.com