lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.94k stars 397 forks source link

Question: How to document methods that accept argument forwarding? #1362

Closed synthead closed 1 week ago

synthead commented 3 years ago

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?

lsegal commented 3 years ago

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(...)