Accessing a value in a method using *
In a method definition, when *
used like this, what does it mean?
def foo(*)
...
end
I understand the following usage:
def foo(*args)
...
end
I'm not sure how to access the method parameters in the first case.
+3
Prasad
source
to share
2 answers
This means "accept and discard any number of parameters."
Both definitions are technically the same, but without specifying the name of the argument array, you cannot access it.
+4
Matheus moreira
source
to share
In the first case, it simply allows the call with arbitrary arguments and discards them.
The second case assigns any arguments to args
0
James kyburz
source
to share