I’ve been trying to get rdoc to document virtual attributes as though
they weren’t virtual. The solution seems to be to use an attr_reader /
attr_writer as an anchor for the documentation with the :nodoc: modifier
on the getter / setter methods, like so:
Documentation for virtual_var.
def virtual_var # :nodoc:
# “get” virtual_var
def virtual_var=(whatever) # :nodoc:
# “set” virtual_var
Doing this results in rdoc documenting the virtual attribute alongside
the normal attributes and not documentating the virtual attribute getter
/ setter methods. So, to the reader, the fact that the attribute is
virtual is completely hidden.
The main problem with this approach seems to be that it places a greater
responsibility on the programmer to ensure that there is no mismatch
between what a ClassName instance reports its variable to be and what
the getter method says it is.
Are there any other potential problems with using this approach?
Is there a better way to do it?