譬如:
def calculate(*numbers, method = {:add=>true})
就一直报错:
syntax error, unexpected '=', expecting ')' (SyntaxError)
检索The Ruby Programming Wikibook 的相关语法也没有提示,请问这是什么原因呢?
黄舟2017-04-24 09:14:26
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.
天蓬老师2017-04-24 09:14:26
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.