Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding a method from YARD (the right way)

Tags:

ruby

yard

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 private badge in the documentation, but still shows them.

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

like image 401
Phrogz Avatar asked Nov 19 '14 15:11

Phrogz


1 Answers

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.

like image 130
Gabriel Avatar answered Oct 31 '22 18:10

Gabriel