Best way to document the splatted parameter with YARD?

I have a method that should accept 1+ parameters of any class, similar to Array # push :

def my_push(*objects) raise ArgumentError, 'Needs 1+ arguments' if objects.empty? objects.each do |obj| puts "An object was pushed: #{obj.inspect}" @my_array.push obj end end 

What is the best way to document method parameters using YARD syntax?

Edit:

I understand that my initial question was too vague and did not quite determine what I was looking for.

A better question would be, what is the best way to specify the arity of the method (1-∞ in this case) in YARD when using the splatted parameter? I know that I can just specify it in the text, but it seems that there should be a tag or something like that to indicate arity.

+7
ruby parameters documentation splat yard
source share
1 answer

The creator of YARD, lsegal, claims to need to do @overload for expected calls . However, this does not give more clarity in the case of the Array#push method.

I suggest you use the @param tag and use Array<Object> as the type of the argument, or provide @overload , which looks good.

Here's a comparison of the two:

 class Test # A test method # # @param [Array<Object>] *args Any number of Objects to push into this collection # @return nil def push(*args); end # Another test method # # @overload push2(obj, ...) # @param [Object] obj An Object to push # @param [Object] ... More Objects def push2(*args); end end 
+7
source share

All Articles