简体   繁体   中英

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";
    }
}
class TheClass
  # @param items   [Array]
  # @param filters [Array<Filter>]
  # @return        [Array<TheClass>]
  def filter(items, filters); end
end

As documented YARD Tags .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM