Documenting attributes using YARD for Plain Old Ruby Objects is fairly straightforward:
But sometimes the attributes are created using metaprogramming. One such example is
dry-struct, a gem built on top of dry-types
which provides a virtus-like DSL for defining typed struct classes:
The shortcoming of this approach is that YARD does not know how to generate documentation from the attribute
declarations. This is where the directive
@!attribute comes in.
It defines an attribute with a given name,
using indented block data as the attribute’s docstring. If the type specifier is supplied with "r", "w", or "rw",
the attribute is made readonly, writeonly or readwrite respectively. A readwrite attribute is the default, if no
type is specified. The comment containing this directive does not need to be attached to any source, but if it is,
that source code will be used as the method’s source.