I am writing a helper that adds an HTML attribute to a link_to tag in rails. So, my thinking is that my helper method should accept any parameters or blocks passed to it, call l
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.
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