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

时间:2012-04-25 18:39:32

标签: ruby documentation 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方法相同但我无法确定如何简单地获取类型正在使用bar的自定义说明返回和/或重载foo的退货说明。

1 个答案:

答案 0 :(得分:1)

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