我正在使用 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
的提示?
最佳答案
从 v0.8.0 开始,您可以使用 @!parse指令:
class Foo
include Moo
# @!parse extend Moo::ClassMethods
end
关于ruby - YARD:记录由包含的模块添加的类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8873018/