据我所知,尼尔斯莱特的答案是非结构化参数列表的最佳答案。
但是对于用于*args
接受任何一组固定的可能参数列表的方法,有@overload
. 例如,对于Enumerable#find_index
,可以这样写:
# 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
这将被记录为:
#find_index(值)⇒整数?
#find_index {|元素| ... } ⇒ 整数?
#find_index ⇒ 枚举器
将enum中的每个条目与 value 进行比较或传递给block。返回评估值为非假的第一个索引。如果没有对象匹配,则返回nil
。
重载:
#find_index(值)⇒整数?
查找指定值的第一个索引。
(...ETC。)