Ruby: how to splicing an array into a Lisp-style list?

This is what I find myself doing sometimes. Say I have a list of arguments. In Lisp, I can go like

`(imaginary-function ,@args)

to call a function with an array converted from one element to the desired number of arguments.

Is there any similar functionality in Ruby? Or am I just using the completely wrong idiom here?

+5
source share
2 answers

Yes! It was called the splat operator.

a = [1, 44]
p(*a)
+9
source

This is the splat statement: function(*list)

+3
source

All Articles