Bug #16514
closedDocumentation mistake for method syntax (splat/array parameter)
Description
Hello,
In the docs for method definition syntax here we find "The array argument must be the last positional argument".
This is, of course, what is shown on the ruby-lang.org and ruby-doc.org pages on method syntax.
This is not true. Example code (2.7)
def test(val1, *vals, val2)
puts val1, vals, val2
puts "val2: #{val2}"
end
test(3, 4, 5, 6, 7)
# test(3, [4, 5, 6], 7) # this code also works
Conclusion: splat/asterisk/array parameters need not be at the end.
I will point out that the documentation for Ruby 2.6.5 has the same apparent documentation mistake. The splat parameter need not go at the end for that version either. I did not test other versions.
I did not find a related issue here on bugs.ruby-lang.org when searching issues for "method syntax", "method.rdoc" or "array parameter", nor did I find a related issue searching the same terms (checking both open and closed issues) on https://github.com/ruby/ruby/pulls
Files