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

前端 未结 1 632
囚心锁ツ
囚心锁ツ 2020-11-27 06:27

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 paramete

相关标签:
1条回答
  • 2020-11-27 06:51

    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.

    0 讨论(0)
提交回复
热议问题