func_get_args
-
We can use variable arguments in Ruby using the glob operator (
*). By prefixing a parameter in your method definition with this operator, you tell the method to combine all remaining arguments for the method into an array for that argument.PHP
function add() { $total = 0; foreach (func_get_args() as $num) { $total += $num; } return $total; } print add(1, 2, 3); // => 6
Ruby
def add(*nums) total = 0 nums.each {|num| total += num } total end # => 6
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

