Hi,
I would like to pass arguments to a function that takes a variable
number of arguments using an array.
For example:
my_array = [1, 2, 3]
# Below should call my_var_arg_function(1, 2, 3)
pass_array_as_args(my_var_arg_function, my_array)
Is this possible in Ruby?
Thanks in advance...
sickfaichezi wrote:
Hi,
I would like to pass arguments to a function that takes a variable
number of arguments using an array.
For example:
my_array = [1, 2, 3]
# Below should call my_var_arg_function(1, 2, 3)
pass_array_as_args(my_var_arg_function, my_array)
my_var_arg_function(*my_array)
It's called the "splat" or "unary un-array" operator.
···
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
Something like this?
def three(arg1, arg2, arg3)
puts "#{arg1}-#{arg2}-#{arg3}"
end
args = [1,2,3]
three(*args)
···
On 9/23/06, sickfaichezi <sickfaichezi@gmail.com> wrote:
Hi,
I would like to pass arguments to a function that takes a variable
number of arguments using an array.
For example:
my_array = [1, 2, 3]
# Below should call my_var_arg_function(1, 2, 3)
pass_array_as_args(my_var_arg_function, my_array)
Is this possible in Ruby?
Thanks in advance...