1

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";
    }
}
Kirby
  • 2,847
  • 2
  • 32
  • 42

1 Answers1

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

As documented YARD Tags.

Hosam Aly
  • 41,555
  • 36
  • 141
  • 182
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145