Following code not work.
def foo(x, **others)
bar(wait: 1, **others) # => syntax error.
end
def bar(wait, **others)
p others
end
foo x: 1, y: 2, z: 3 # => the expected output: {y: 2, z: 3}
But following code works
def foo(x, **others)
bar(1, **others) # => works
end
def bar(wait, **others)
p others
end
foo x: 1, y: 2, z: 3 # => the expected output: {y: 2, z: 3}
This leads to a problem, if foo
want to use double splatting to forward arguments to bar
,
the bar can not force use named argument, signature like this never work. def bar(*, wait, **others)
.
is there any reason for the first code is invalid?
Thanks.