Neil Slater's answer is as far as I know the best one for an unstructured argument list.
But for methods that use *args
to accept any of a fixed set of possible parameter lists, there's @overload
. E.g., for Enumerable#find_index
, one could write something like:
# Compares each entry in _enum_ with value or passes to _block_.
# Returns the index for the first for which the evaluated value
# is non-false. If no object matches, returns `nil`.
#
# @overload find_index(value)
# Finds the first index of the specified value.
# @param value [Object] the value to find
# @return [Integer, nil] the index, or `nil` if no element matches
# @overload find_index(&block)
# Finds the index of the first value matching
# the specified block.
# @yieldparam [Object] element the element to match against
# @yieldreturn [Boolean] whether the element matches
# @return [Integer, nil] the index, or `nil` if no element matches
# @overload find_index
# @return [Enumerator] a new enumerator
def find_index(*args)
# (...)
end
This will get documented as:
#find_index(value) ⇒ Integer?
#find_index {|element| ... } ⇒ Integer?
#find_index ⇒ Enumerator
Compares each entry in enum with value or passes to block.
Returns the index for the first for which the evaluated value
is non-false. If no object matches, returns nil
.
Overloads:
#find_index(value) ⇒ Integer?
Finds the first index of the specified value.
(...etc.)