-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Ideally there would be a way to distinguish between these two method calls
module Bar
def self.example1(value)
end
def self.example2(value)
end
end
Bar.example1(String.new)
Bar.example2(String)but unfortunately it seems like the best you can do is either
-
Write a pretty unhelpful doc like so
# @param value [Class] def self.example2(value) endthis is correct but preferably it would say that it ONLY takes the
Stringclass if that is the contract -
Write an incorrect but helpful doc like so
# @param value [String] def self.example2(value) endthis means an instance of
Stringbut a lot of people write this anyways because it is usually clear with context -
Write an invalid but helpful and syntactically different doc like so
# @param value [Class:String] def self.example2(value) endYARD doesn't support this
Class:Blahsyntax but it does differentiate from "an instance ofString" and it is also helpful.
I'm not really interested in supporting a superset of YARD type annotations (unless yardcheck really took off I guess and Loren had more or less officially moved on from ruby / YARD). I also think it is dumb to tell people to make their documentation useless by writing @param value [Class] and maybe writing a note after the docs. The point of YARD is to have good metadata alongside docs.
I think the best solution is basically supporting the ambiguous syntax until a better alternative is clear. Therefore, both example1 and example2 would be documented the same way (@param value [String]) and the check would look like
observed_value.is_a?(String) || (observed_value.is_a?(Module) && observed_value < String)