带变量的Ruby参数SyntaxError


    def a(b: 88, c: 97)
      puts b
      puts c
    end

上面的代码可以工作。但是,

def a(b: 88, c: 97, *c)
  puts b
  puts c
end

抛出语法错误。谁能给我指出正确的文档来解释它?

位置参数在方法签名中优先出现。命名参数放在最后。

这将更好地工作,但您仍然有一个重复的参数名称,这是不允许的。

def a(*c, b: 88, c: 97)
  puts b
  puts c
end
# ~> -:1: duplicated argument name
# ~> def a(*c, b: 88, c: 97)
# ~>                    ^

在Ruby中混合关键字和常规参数?

最新更新