ruby - How can I prevent a positional argument from being expanded into keyword arguments? -
i'd have method accepts hash , optional keyword argument. tried defining method this:
def foo_of_thing_plus_amount(thing, amount: 10) thing[:foo] + amount end
when invoke method keyword argument, works expect:
my_thing = {foo: 1, bar: 2} foo_of_thing_plus_amount(my_thing, amount: 20) # => 21
when leave out keyword argument, however, hash gets eaten:
foo_of_thing_plus_amount(my_thing) # => argumenterror: unknown keywords: foo, bar
how can prevent happening? there such thing anti-splat?
this bug fixed in ruby 2.0.0-p247, see this issue.
Comments
Post a Comment