rdoc icon indicating copy to clipboard operation
rdoc copied to clipboard

Documenting `Data` classes

Open halostatue opened this issue 8 months ago • 0 comments

rdoc does not usefully document data classes defined the correct way:

# Documenting a class made with Data.define
MyDataClass = Data.define :a do
  # Capitalize the value of +a+.
  def cap
    a.capitalize
  end
end

This documents a constant on Object, Object::MyDataClass instead of documenting it as a class itself, and the method within the data class definition is not documented either. It does not matter whether the Prism parser is used.

When documented with reopening, there are two different issues

MyDataClass = Data.define :a # :nodoc:

# Documenting a class made with Data.define
class MyDataClass
  # Capitalize the value of +a+.
  def cap
    a.capitalize
  end
end

If defined without # :nodoc:, MyDataClass is still documented as a constant on Object; if defined with # :nodoc:, the documentation is removed, but the generated documentation pages for Object isn't removed.

I believe that Data.define and Struct.new should be treated as if they were written as class variants.

halostatue avatar Jun 01 '25 16:06 halostatue