1

I've ecountered this today and I have no idea what it means. I tried to google it but I had no luck. Can someone explain this to me?

combinations.each do |combination|
  messages = EventNotification.where('user_id = ? AND message_template = ?', *combination)
  ...
end

1 Answers1

3

It's called the splat operator, and it unpacks an array into single method arguments. In this case, because the function presumably expects two more arguments after the format string, it's equivalent to:

messages = EventNotification.where('user_id = ? AND message_template = ?',
                                   combination[0], combination[1])

In other languages, this feature is often called "varargs".

Thomas
  • 174,939
  • 50
  • 355
  • 478