亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

ruby - 方法可變參數(shù)(如*options)之后的參數(shù),不可以設(shè)置默認(rèn)值嗎?
伊謝爾倫
伊謝爾倫 2017-04-24 09:12:26
0
3
814

譬如:

def calculate(*numbers, method = {:add=>true})

就一直報(bào)錯(cuò):

syntax error, unexpected '=', expecting ')' (SyntaxError)

檢索The Ruby Programming Wikibook 的相關(guān)語法也沒有提示,請(qǐng)問這是什么原因呢?

伊謝爾倫
伊謝爾倫

小伙看你根骨奇佳,潛力無限,來學(xué)PHP伐。

reply all(3)
黃舟

Suppose you are the interpreter, what would you do with calculate({add: true}) 中的參數(shù) {add: true} 分配給 *numbers 呢,還是 method?

You can’t judge at all, right? So it's not allowed.

Peter_Zhu

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template