method1 a b, c
If so, which method argument is c?
In Ruby, you don't have to put commas or parentheses in the method arguments. However, in the case of this system, I think that a problem will occur. So, this time, I actually tried it and verified it. I was wondering about the following questions because there weren't many articles.
For example
method1 a, b
Is
method1(a, b)
It means (I got an error when I tried to define a method with the name method, so I set it as method1.).
method1 a b
Is
method1(a(b))
It means that. It's good so far (although it's already a little strange at this point ... it's tough for beginners ...)
method1 a b, c
Isn't there two possibilities?
method1(a(b),c)
When
method1(a(b,c))
Both possibilities.
What you should check here is
is. You just need to confirm this. (At this point, it's tough for the reader.) But what about variadic arguments? Perhaps one of them has priority. ..
Now, let's verify which of the above patterns is used.
def a *temp
p "The number of arguments to a is"
p temp.size
end
def method1 *temp
p "The number of arguments of method1 is"
p temp.size
end
Result is,,,
method1 a 1, 2
# "The number of arguments to a is"
# 2
# "The number of arguments of method1 is"
# 1
That is, the above
method1(a(1, 2))
Was received. It seems that the above possibility 2 has been adopted.
Recommended Posts