动态文档,使用另一个YARD描述中的方法返回?

我正在记录一个项目,并且我有类似于以下内容:

def foo return bar(__method__) end def bar (method) return method.to_s + 'somestring' end 

我正在设置多种类似于我实现foo的方法,他们正在返回bar的返回值。 一个例子如下:

 # The descriptions for foo0... # @return [String] the method name concatenated with somestring def foo0 return bar(__method__) end # The descriptions for foo1... # @return [String] the method name concatenated with somestring def foo1 return bar(__method__) end # The descriptions for bar... # @return [String] the method name concatenated with somestring def bar (method) return method.to_s + 'somestring' end 

但是说我改变了哪个bar返回一个整数然后我的文档是不正确的。 我熟悉在YARD中记录DSL,但是如何在描述另一种方法时指定#bar@return.type返回方法bar的返回类型。 我所指的一个例子如下:

 # The descriptions for foo0... # @return [#bar@return.type] the method name concatenated with somestring def foo0 return bar(__method__) end # The descriptions for foo1... # @return [#bar@return.type] the method name concatenated with somestring def foo1 return bar(__method__) end # The descriptions for bar... # @return [String] the method name concatenated with somestring def bar (method) return method.to_s + 'somestring' end 

最终我要完成的是记录我的代码,而不必像返回类型那样定义绝对值,这取决于定义的另一种方法。

更新:我发现你能够调用# @return (see #bar)并让它列出返回或foo方法与bar方法相同但我无法确定如何简单地获取返回的类型和/或使用foo的自定义描述重载bar的返回描述。

正如您所发现的,您应该使用@return (see #bar)@return标记从#bar逐字复制到其他文档字符串。 注意:它也会复制描述文本。 没有办法只插入方法的类型。 但是,在您的具体示例中,您似乎并不需要它。