We create a method with splatted arguments and call Method#parameters
on it:
def splatter(x, *y, z); end
params = method(:splatter).parameters
# => [[:req, :x], [:rest, :y], [:req, :z]]
I'm looking for a function f
that will map a list of arguments onto their corresponding variable names. The function should be flexible enough to work on any other method with arbitrarily placed splat arguments. For example:
args = [:one, :two, :three, :four]
f(params, args)
# => [[:x, :one], [:y, :two], [:y, :three], [:z, :four]]
or something along those lines (flipped elements would be fine also). I feel there must be a flexible, elegant solution using inject
or something, but I can't seem to come up with it.