我的类将一个方法委托给另一个对象(我称之为helper对象)。我希望在委托类中包含该方法的文档,而不仅仅是委托类。程序员不应该使用helper对象,而应该只使用main对象,所以在helper对象中编写文档并不是很有用。
考虑这个例子。Rdoc输出有关Node#initialize和Helper#hello的文档。我希望有关于Node#hello的文档,就好像它只是另一种方法一样。有没有办法做到这一点?
require 'forwardable'
class Node
extend Forwardable
delegate %w(hello) => :@helper
# Takes no params.
def initialize
@helper = Helper.new()
end
end
class Helper
# Outputs 'hello world'
def hello
puts 'hello world'
end
end-更新--
我试过了。yard命令如下所示:
yardoc --no-private --protected app/**/*.rb -我编辑了拼音代码,尝试为Node#hello添加文档:
class Node
extend Forwardable
delegate %w(hello) => :@helper
# Takes no params.
def initialize
@helper = Helper.new()
end
# @!method hello
# Documentation for Node#hello
end当我运行yardoc时,它似乎是在处理三个方法:
Files: 1
Modules: 0 ( 0 undocumented)
Classes: 2 ( 2 undocumented)
Constants: 0 ( 0 undocumented)
Attributes: 0 ( 0 undocumented)
Methods: 3 ( 0 undocumented)
60.00% documented如果我没有# @!method指令,那么它只处理两个方法:
Files: 1
Modules: 0 ( 0 undocumented)
Classes: 2 ( 2 undocumented)
Constants: 0 ( 0 undocumented)
Attributes: 0 ( 0 undocumented)
Methods: 2 ( 0 undocumented)
50.00% documented所以它看起来像是Node#hello的文档,但它并没有出现在实际的文档中:

所以我不知道接下来该怎么做。
发布于 2021-01-05 03:30:07
在@max的建议下,我转到了yard。使用yard,我可以在没有任何实际方法的情况下创建方法文档,如下所示:
# @!method hello()
# Outputs "hello world"
delegate %w(hello) => :@helper值得注意的是,文档必须在实际代码之上。如果它是单独的,它就不会工作。
https://stackoverflow.com/questions/65565711
复制相似问题