如何防止位置参数扩展为关键字参数?

ænd*_*rük 9 ruby arguments keyword-argument ruby-2.0

我想要一个接受哈希和可选关键字参数的方法.我尝试定义这样的方法:

def foo_of_thing_plus_amount(thing, amount: 10)
  thing[:foo] + amount
end
Run Code Online (Sandbox Code Playgroud)

当我使用关键字参数调用此方法时,它按预期工作:

my_thing = {foo: 1, bar: 2}
foo_of_thing_plus_amount(my_thing, amount: 20) # => 21
Run Code Online (Sandbox Code Playgroud)

但是,当我省略关键字参数时,哈希会被吃掉:

foo_of_thing_plus_amount(my_thing) # => ArgumentError: unknown keywords: foo, bar
Run Code Online (Sandbox Code Playgroud)

我怎样才能防止这种情况发生?有没有像防摔这样的东西?

Mar*_*une 4

这是 Ruby 2.0.0-p247 中修复的一个错误,请参阅此问题