Just trying to understand how to collect arguments in Ruby, I came up with the following snippet, that seems to fail to collect keyword arguments
in **kargs
in some case:
def foo(i, j= 9, *args, k: 11, **kargs)
puts "args: #{args}; kargs: #{kargs}"
end
foo(a: 7, b: 8)
# output: args: []; kargs: {}
foo(9, a: 7, b: 8)
# output: args: []; kargs: {:a=>7, :b=>8}
foo(9, 10, 13, a: 7, b: 8)
# output: args: [13]; kargs: {:a=>7, :b=>8}
I would like to know why it does not collect kargs
in the first call to foo
, while in the second call it does.