Ruby 参数关键字 **
2019/09/12
如果不知道后面可能用到什么参数,最后一个参数可以直接写成 **
(Double **Splat),它会接受所有 hash 类型的参数
def test(a, b, **others)
p a, b, others, others[:test], others[:no_key]
end
test(1, 2, test: 'test string', test_another: 'test another string')
=>
1
2
{:test=>"test string", :test_another=>"test another string"}
"test string"
nil
参考: