84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
譬如:
def calculate(*numbers, method = {:add=>true})
就一直报错:
syntax error, unexpected '=', expecting ')' (SyntaxError)
检索The Ruby Programming Wikibook 的相关语法也没有提示,请问这是什么原因呢?
小伙看你根骨奇佳,潜力无限,来学PHP伐。
Suppose you are the interpreter, what would you do with calculate({add: true}) 中的参数 {add: true} 分配给 *numbers 呢,还是 method?
calculate({add: true})
{add: true}
*numbers
method
You can’t judge at all, right? So it's not allowed.
Can’t this kind of *numbers variable parameters only be at the end?
def calc(method = {add: true}, *numbers); end is allowed, but the reverse is not allowed.
def calc(method = {add: true}, *numbers); end
Not allowed, there will be ambiguity
Suppose you are the interpreter, what would you do with
calculate({add: true})
中的参数{add: true}
分配给*numbers
呢,还是method
?You can’t judge at all, right? So it's not allowed.
Can’t this kind of
*numbers
variable parameters only be at the end?def calc(method = {add: true}, *numbers); end
is allowed, but the reverse is not allowed.Not allowed, there will be ambiguity