5

This is something I find myself wanting to do occasionally. Say I have a list of arguments. In Lisp, I can go like

`(imaginary-function ,@args)

in order to call the function with the array turned from one element into the right number of arguments.

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

TG-T
  • 2,174
  • 3
  • 19
  • 20

2 Answers2

9

Yes! It's called the splat operator.

a = [1, 44]
p(*a)
David Grayson
  • 84,103
  • 24
  • 152
  • 189
3

This is the splat operator: function(*list)

dfb
  • 13,133
  • 2
  • 31
  • 52