譬如:
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