Expanding array as function arguments

Hi!
I wonder if it is possible to expand array as function arguments. Like

def foo( a, b, c)
end

foo [1,2,3].to_args

Is possible to do it?

···

--
Witold Rugowski
http://nhw.pl/wp/ (EN blog)
http://FriendsFeedMe.com
--
Posted via http://www.ruby-forum.com/.

foo *[1,2,3]

(
similar to grouping several arguments into an array if method definition:

def foo(*args)
end

foo 1, 2, 3
)

···

On Dec 5, 2007 1:43 PM, Witold Rugowski <rugowski@nhw.pl> wrote:

Hi!
I wonder if it is possible to expand array as function arguments. Like

def foo( a, b, c)
end

foo [1,2,3].to_args

Is possible to do it?

--
Sergio Gil Pérez de la Manga
e-mail > sgilperez@gmail.com
blog > http://www.lacoctelera.com/porras

foo *[1,2,3]

robert

···

2007/12/5, Witold Rugowski <rugowski@nhw.pl>:

Hi!
I wonder if it is possible to expand array as function arguments. Like

def foo( a, b, c)
end

foo [1,2,3].to_args

Is possible to do it?

--
use.inject do |as, often| as.you_can - without end

Hi!
I wonder if it is possible to expand array as function arguments. Like

def foo( a, b, c)
end

foo [1,2,3].to_args
Is possible to do it?

How about foo *[1, 2, 3] ? (Note the "*" -"splat").

···

--
Regards,
Rimantas
--
http://rimantas.com/

Sergio Gil Pérez de la Manga wrote:

foo *[1,2,3]

(
similar to grouping several arguments into an array if method
definition:

def foo(*args)
end

foo 1, 2, 3
)

Thnx a lot :wink:

···

--
Posted via http://www.ruby-forum.com/\.

A note on splat; it can be used to both gather and unpack elements,
depending on the context. For example...

def baz(a, b, c)
p a, b, c
end
def foo(*bar) # gathering - bar = [1, 2, 3]
  baz(*bar) # unpacking - bar = 1, 2, 3
end
foo(1, 2, 3)

Regards,
Jordan

···

On Dec 5, 7:13 am, Witold Rugowski <rugow...@nhw.pl> wrote:

Sergio Gil Pérez de la Manga wrote:

> foo *[1,2,3]

> (
> similar to grouping several arguments into an array if method
> definition:

> def foo(*args)
> end

> foo 1, 2, 3
> )

Thnx a lot :wink:
--
Posted viahttp://www.ruby-forum.com/.