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
?
Since v0.8.0 you can use the @!parse directive:
class Foo
include Moo
# @!parse extend Moo::ClassMethods
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With