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

标签 ruby module class-method 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 类生成如下所示的文档:

Inadequate documentation of the Foo class

我认为此文档不充分,因为它没有告诉用户 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/

相关文章:

ruby - 文件中的 Aws Ruby SDK 凭证

ruby - 在 Ruby 中解析大文件的最快方法

python - PyCharm 错误 : 'No Module' when trying to import own module (python script)

ios - 无法在 Swift 中跨模块访问属性包装器

python - 创建 python 工厂方法

python - 为什么我不能在类方法中使用 python 模块 concurrent.futures?

ruby - 为什么要使用 Ruby 的 DBM 库

module - 如何在模块内使用模块?

python - super 和 __new__ 混淆

ruby-on-rails - 在 Rails 中,如何制作 :mobile views to fallback default views when not found?