Search code examples
rubyrdocyard

YARD how to document a @param of Array<Array<String>>


Let's say I have the following function:

@param foo [Array<String>]
def recursive_split(foo)
  bar = []
  foo.each do |elem|
    bar.append(elem.split(''))
  end
  bar
end

How do I document with the yard @return tag that my return value is an array of arrays of strings ? Is @return [Array<Array<String>>] the right way to do it ?


Solution

  • The docs aren't that specific but types specifiers are recursive so the X in Array<X> can be any list of valid types so these:

    Array<String>
    Array<String, Symbol>
    Array<Array<String, Symbol, #m>>
    Array<String, Array<#m>>
    ...
    

    are all valid.

    The online type parser is probably the easiest way to check. That says that Array<Array<String>> is:

    an Array of (an Array of (Strings))