Defining a recursive method that takes several arguments
What do I define a recursive method with variable arguments in ruby?
I was thinking
def meth(var, *var)
meth(var,var)
end
If I do it like that, var becomes an array 开发者_运维技巧in the next iteration.
Use the splat when you call it as well (like you would with & when passing a block rather than defining one):
def meth(var, *var)
meth(var,*var)
end
Least surprise!
精彩评论