Here is a powerful and concise Ruby pattern for dealing with splat keyword arguments. In this example, a
and b
are both required, and all other arguments live in rest
.
def method(a:, b:, **rest)
puts "a is #{a}, b is #{b}, rest is #{rest}"
end
>>> method({ a: '1', b: '2', c: '3', d: '4' })
a is 1, b is 2, rest is {:c=>"3", :d=>"4"}