I would like to document a few methods in an anonymous class for rdoc.
I know that alternative documetation tool exists, such as yard, but not sure the project owners are ready for change they inventory for sake of few methods.
I tried :method: and :doc: directives, but no luck so far
Tried with ruby 2.7, rdoc 6.6.2
# (c) 2024 Big Corporation
# = ExampleModule gives a great example to all of us
#
# This module contains an example of documenting an anonymous class created with Class.new.
module ExampleModule
# Create an anonymous class using Class.new, almost the same as
# class AnonymousClass
# and give a closure
# but fails rdoc
AnonymousClass = Class.new do
##
# :method: initialize
# This is a initializer with two parameters
def initialize(param1, param2)
# ... initialization code ...
end
##
# :method: example_method
# == example_method
#
# An example method in the anonymous class.
def example_method
# ... method implementation ...
end
end
end
Apparently, if method comments in my example moved before the AnonymousClass, definition, they will appear (in the same HTML page). Of course, class would no be find-able, and some comments are needed to clarify that methods relate to the class, not the module
Note. In the real code I was not even able to add AnonymousClass description to rdoc constant section, but seems to work fine with the above small example. But I guess constant skipping might require this is not necessary related issue.