Variadic function

A parameter declared with "*", can take any number of arguments of any type.

func print_all(*things) {
    things.each { |x| say x }
}

This function can be called with any number of arguments:

print_all(4, 3, 5, 6, 4, 3)
print_all(4, 3, 5)
print_all("Rosetta", "Code", "Is", "Awesome!")

Also, there is "..." which transforms an array into a list of arguments.

var args = ["Rosetta", "Code", "Is", "Awesome!"]
print_all(args...)

Last updated