YARD:记录包含的模块添加的类方法
我正在使用 YARD 为我的 ruby gem 编写文档。在我的 gem 中,我有一些代码遵循这种常见的 ruby 模式,其中模块包含在类中,并且该模块不仅添加实例方法,还添加类方法:
module Moo
def self.included(klass)
klass.extend ClassMethods
end
module ClassMethods
def hello
puts "hello"
end
end
end
class Foo
include Moo
end
Foo.hello # => class method runs, printing "hello"
默认情况下,YARD 将为 Foo 类生成文档看起来像这样:
我认为这个文档不充分,因为它确实不告诉用户Foo.hello
方法可用。要了解 hello
,用户必须单击 Moo
,然后单击 ClassMethods
。
如果能在一页上列出 Foo
的所有类和实例方法,那就太好了。我怎样才能做到这一点?我是否需要更改代码,或者是否可以添加一个标签来为 YARD 提供有关 ClassMethods
的提示?
I am writing documentation for my ruby gem using YARD. In my gem, I have some code which follows this common ruby pattern where a module is included in a class, and that module not only adds instance methods but it also adds class methods:
module Moo
def self.included(klass)
klass.extend ClassMethods
end
module ClassMethods
def hello
puts "hello"
end
end
end
class Foo
include Moo
end
Foo.hello # => class method runs, printing "hello"
By default, YARD will generate documentation for the Foo class that looks like this:
I think this documentation is inadequate because it does not tell the user that the Foo.hello
method is available. To learn about hello
, the user has to click on Moo
and then click on ClassMethods
.
It would be great to have a list of all the class and instance methods of Foo
on one page. How can I make that happen? Do I need to change the code, or is there a tag I can add to give YARD a hint about ClassMethods
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 v0.8.0 开始,您可以使用 @!parse 指令:
Since v0.8.0 you can use the @!parse directive: