yard icon indicating copy to clipboard operation
yard copied to clipboard

Question: How to document methods that accept argument forwarding?

Open synthead opened this issue 3 years ago • 1 comments

Ruby 2.7 introduces argument forwarding, which looks like this:

def accept_any_args(...)
  call_with_any_args(...)
end

If argument forwarding is used with YARD, one might attempt to document their methods like this:

# Inspects some options.
#
# @param [Hash] options Options to inspect.
# @return [String] Inspected object.
def my_method(...)
  private_method(...)
end

private

def private_method(**options)
  options.inspect
end

However, when yardoc is ran with the above code, it raises this warning:

[warn]: @param tag has unknown parameter name: options 

How should the above code be documented with YARD?

synthead avatar Nov 23 '20 21:11 synthead

The general approach here would be the same as the case where you have a *args or **kwargs method-- you would use @overload to define a synthesized method signature:

# @overload my_method(a, b)
#   @param a [String] the first parameter
#   @param b [Boolean] the second parameter
def my_method(...) = other(...)

lsegal avatar Dec 27 '20 04:12 lsegal