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:
- Array to Arguments Conversion
Use this
a.slice(*b)
It's called the splat operator