rubyrubyminerdoc

How to declare array of a particular type in ruby documentor?


I'd like to declare an array of objects with the exact object class in rubydoc for either a parameter or variable, or for @return. (it must be RDoc?..)

The main reason, to make RubyMine (or another IDE) work for autocomplete stuff, clickable methods, refactoring, etc., in right way.

In PHP will look like:

/**
 * @param array $items
 * @param Filter[] $filters
 * @return Result[]
 */
function filter($items, $filters) {}

I'm just not sure if it can work in similar way in RubyMine:

##
# @param [Array] items
# @param [Filter[]] filters
# @return [ResultClass[]]
#
def filter(items, filters); end

Extra example in PHP:

class My
{
    public $name;
}

/**
 * @return My[]
 */
function foo()
{
      // Similar code here
      //return [new My(), new My()];
}

function show()
{
    foreach (foo() as $item) {
        // IDE will make autocomplete for My::$name
        echo "$item->name\n";
    }
}

Solution

  • class TheClass
      # @param items   [Array]
      # @param filters [Array<Filter>]
      # @return        [Array<TheClass>]
      def filter(items, filters); end
    end
    

    As documented YARD Tags.