Hiding a method from YARD (the right way)

2.3k views Asked by At

I am using YARD to document one of my Ruby projects. I have certain methods that I do not want to be included in the documentation, things like #inspect and #to_s that you expect to exist and return a reasonable result.

It is possible to hide these methods using the @private tag and the yardoc --no-private command-line option:

# @private let's not document this
def inspect; ...; end

However, the YARD documentation on @private explicitly states:

Note: This method is not recommended for hiding undocumented or “unimportant” methods. This tag should only be used to mark objects private when Ruby visibility rules cannot do so.

If I use @api private instead, YARD (nicely) tags the methods with a badge in the documentation, but still shows them.

Is there a "legal" way to hide methods from YARD output?

1

There are 1 answers

1
Gabriel On BEST ANSWER

From my limited tests, I noticed the following works well (and doesn't have the explicit note in the documentation to avoid for your use case):

# @!visibility private
def inspect; ...; end

According to the yard documentation:

@!visibility public | protected | private

Modifies the current parsing visibility (public, protected, or private).

Hope that helps.