rubyyard

YARD how to document @return type for a method that returns fixed-size array?


I have the following method:

def foo
  [true_or_false, some_integer]
end

it always returns an array of 2 where 1st element is boolean and 2nd is integer. How to document it in YARD using @return meta tag?

That's how it is later used:

is_success, exit_code = foo

I've checked the official documentation on @return section but it didn't help much.


Solution

  • # @return [Array(Boolean, Number)] fixed-size array(vector) of a boolean followed by a number
    def foo
      [true_or_false, some_integer]
    end
    

    Do not confuse it with other similar @return tag format:

    # @return [Array<String, Symbol, #read>] an Array of (Strings, Symbols, objects that respond to #read)
    

    which is for variable-length arrays of different data types, not for fixed-length vectors.