YARD:记录由包含的模块添加的类方法

时间:2021-08-13 23:22:59

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:

我正在使用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"

By default, YARD will generate documentation for the Foo class that looks like this:

默认情况下,YARD将生成Foo类的文档,如下所示:

YARD:记录由包含的模块添加的类方法

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.

我认为这个文档是不合适的,因为它没有告诉用户Foo.hello方法是可用的。要了解hello,用户必须单击Moo然后单击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?

在一个页面上拥有Foo的所有类和实例方法的列表会很棒。我怎么能做到这一点?我是否需要更改代码,或者是否有我可以添加的标签,以便为YARD提供有关ClassMethods的提示?

1 个解决方案

#1


7  

Since v0.8.0 you can use the @!parse directive:

从v0.8.0开始,你可以使用@!parse指令:

class Foo
  include Moo
  # @!parse extend Moo::ClassMethods
end

#1


7  

Since v0.8.0 you can use the @!parse directive:

从v0.8.0开始,你可以使用@!parse指令:

class Foo
  include Moo
  # @!parse extend Moo::ClassMethods
end