【发布时间】:2012-04-25 18:39:31
【问题描述】:
我正在记录一个项目,基本上我有类似以下内容:
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) 并让它列出与bar 方法相同的返回或foo 方法,但我无法确定如何简单地获取正在返回的类型和/或用foo 的自定义描述重载bar 的返回描述。
【问题讨论】:
标签: ruby documentation yard