class YARD::Tags::TypesExplainer::GroupType
@private
Attributes
Public Class Methods
Source
# File lib/yard/tags/types_explainer.rb, line 98 def initialize(types) @types = types end
Public Instance Methods
Source
# File lib/yard/tags/types_explainer.rb, line 102 def to_s(singular = true) "(" + list_join(types.map {|t| disambiguate(t, singular) }) + ")" end
Private Instance Methods
Source
# File lib/yard/tags/types_explainer.rb, line 117 def disambiguate(type, singular) rendered = type.to_s(singular) needs_parens = type.is_a?(IntersectionType) || (type.is_a?(DuckType) && type.name.include?('&')) needs_parens ? "(#{rendered})" : rendered end
{IntersectionType} and a multi-method {DuckType} (‘#foo & bar`) both render as a bare “X and Y”, with no punctuation of their own to mark where they end. Sitting next to a sibling in this group’s own “or”-joined list, that reads ambiguously (e.g. “a Foo and a Bar or a Baz” doesn’t show whether the “and” or the “or” binds tighter) even though the parse itself is unambiguous. Wrap those two cases in their own parens so the group’s members are visually self-delimiting; every other {Type} already is (a bare name, or something with its own bracketing like {GroupType} itself).