Hi,
This isn't a case where custom handlers would not be applicable, and
the macro as defined above would not work.
It looks like you just want to document attributes though, and that can
be done fairly easily in a number of ways.
Just FYI, before I show any examples, some IMPORTANT NOTES!
1. YARD already generates standard documentation for attributes that
look almost exactly like how you are documenting them. If all you're
doing is the above-- don't do it. It doesn't provide anything YARD
doesn't do already.
2. If you're not providing ANY extra documentation, you're not really
providing any usable benefit to your users here except listing method
names. You can do this by just creating attrs: attr_reader :name, :type,
...
3. Adding a docstring of "Returns ___" and a @return tag is redundant.
Your @return tag is the Returns sentence, and YARD will generate this
docstring for you.
Okay, now the examples:
1. Regular macros on attrs:
# @!macro [new] attr
# @return [String] the ivar $1
# @!macro attr
attr_reader :name
# @!macro attr
attr_reader :type
2. Define a mini-DSL:
If you're doing something more complicated than *just* attrs, you can
define a mini DSL and document that with attached macros:
class MyClass
# @!macro [attach]
# @!attribute [r] $1
# @return [String] the ivar $1
def self.myattr(attr)
define_method(attr) { @my_ivar[attr] }
end
myattr :name
myattr :type
end
Hope that helps,
Loren