Ruby: How do I pass all parameters and blocks received by one method to another?
Solution 1:
You can use *
and &
in method calls to turn arrays back into lists of arguments and procs back into blocks. So you can just do this:
def myhelper(*args, &block)
link_to(*args, &block)
# your code
end
Solution 2:
def method(...)
Starting from Ruby 2.7 it is possible to pass all the arguments of the current method to the other method using (...)
.
So, now,
def my_helper(*args, &block)
link_to(*args, &block)
# your code
end
can be rewritten as
def my_helper(...)
link_to(...)
# your code
end
Here is the link to the feature request.