Accessing a value in a method using *

后端 未结 2 1381
花落未央
花落未央 2021-01-20 13:49

In a method definition, when * is used in the following manner, what does it mean?

def foo(*)
   ...
end

I understand the foll

相关标签:
2条回答
  • 2021-01-20 14:12

    In the first case it just allows calling with arbitrary arguments and discards them.

    The second case assigns any called arguments to args

    0 讨论(0)
  • 2021-01-20 14:34

    It means "take and discard any number of parameters".

    Both definitions are technically the same, but not giving a name to the argument array means you can't access it.

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