Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

naked asterisk as parameter in method definition: def f(*)

Tags:

I know what this means:

def f(*args)   ... end 

But what does this mean and why would you want to use it? Can it appear with named parameters, too?

def f(*)   ... end 
like image 429
pilcrow Avatar asked Mar 09 '11 17:03

pilcrow


1 Answers

def f(*) has the same effect as def f(*args), except that it does not name the globbed argument array. You might use it if you want the function to accept any number of arguments but don't actually need to refer to them within the function -- for example, if you are overriding a method but calling super without passing an explicit argument list, which results in the original arguments being passed to super.

You can write def f(a, b, *) as well.

like image 137
John Avatar answered Oct 21 '22 23:10

John