动态文档,使用返回方法在另一个YARD的描述? [英] Dynamic documentation, using the return of method in the description of another YARD?
问题描述
def foo
/ pre>
返回列表我正在记录一个项目,在本质上我有类似于以下内容: (__method__)
end
def bar(method)
return method.to_s +'somestring'
end
我正在设置大量的方法,类似于我如何实现foo,他们正在返回bar的返回。一个例子如下:
#foo0的描述...
#@return [String]方法名称与somestring连接
def foo0
返回条(__ method__)
end
#foo1 ...
#@return [String]的方法名称连接的描述with somestring
def foo1
return bar(__ method__)
end
#bar的描述...
#@return [String]方法名称与somestring连接
def bar(method)
return method.to_s +'somestring'
end
但是说我改变了什么
bar
返回一个整数,那么我的文档是不正确的。我熟悉在YARD中记录DSL,但是如何只指定#bar@return.type
返回类型的方法bar
描述另一种方法。我所提到的一个例子如下:#foo0 ...
#返回[#bar@return.type]与somestring连接的方法名称
def foo0
返回条(__ method__)
end
#foo1 ... $ b $的说明b#@return [#bar@return.type]与somestring连接的方法名称
def foo1
return bar(__ method__)
end
# bar ...
#@return [String]方法名称与somestring连接
def bar(method)
return method.to_s +'somestring'
end
最终我要完成的是记录我的代码,而不必定义绝对类型,如依赖于另外一种方法是定义为。
更新:
我发现你可以调用#@return(见# bar)
,并将其列出与bar相同的返回值或
foo
/ code>方法,但我无法确定如何简单地获取正在返回的类型和/或使用自定义重载bar
的返回描述foo
的描述解决方案如你所见,你应该使用
@return(请参阅#bar)
以将#code> @return 标签从#bar逐字复制到其他文档字符串。注意:它也会复制描述文本。没有办法只是插入方法的类型。不过,您的具体示例似乎不需要它。I am documenting a project and essientially I have something similar to the following:
def foo return bar(__method__) end def bar (method) return method.to_s + 'somestring' end
I am setting up a multitude of methods similar to how I have implemented foo where they are they are returning the return of bar. An example is as follows:
# 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
But say I change what
bar
is returning to an integer then my documentation is incorrect. I familiar with documenting DSLs in YARD but how do you just specify#bar@return.type
the return type of The return of methodbar
when describing another method. An example of what I am referring to is as follows:# 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
Ultimately what I am trying to accomplish is to document my code without having to define absolutes like a return type which are dependent on what another method is defined to be.
UPDATE: I have discovered that you are able to call
# @return (see #bar)
and have it list the return or thefoo
methods the same asbar
methods but I am unable to determine how to simple get the type which is being returned and/or overload the description of the return forbar
with a custom description forfoo
.解决方案As you discovered, you should use
@return (see #bar)
to copy the@return
tag from #bar verbatim to the other docstrings. Note: it will copy the description text too. There's no way to just interpolate the type of a method. You don't seem to need it in your specific example, though.这篇关于动态文档,使用返回方法在另一个YARD的描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!