ruby convert array into function arguments ruby convert array into function arguments arrays arrays

ruby convert array into function arguments


You can turn an Array into an argument list with the * (or "splat") operator:

a = [0, 1, 2, 3, 4] # => [0, 1, 2, 3, 4]b = [2, 3] # => [2, 3]a.slice(*b) # => [2, 3, 4]

Reference:


Use this

a.slice(*b)

It's called the splat operator