Project

General

Profile

Actions

Bug #16514

closed

Documentation mistake for method syntax (splat/array parameter)

Added by adamisom (Adam Isom) over 4 years ago. Updated about 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:96917]

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

2844.patch.txt (1.27 KB) 2844.patch.txt adamisom (Adam Isom), 01/16/2020 09:54 PM
Actions #1

Updated by adamisom (Adam Isom) over 4 years ago

  • Subject changed from Documentation mistake for method syntax (a splat parameter does not need to be at the end) to Documentation mistake for method syntax (splat/array parameter)

Updated by adamisom (Adam Isom) over 4 years ago

I've submitted Github pull request 2844 here

I've attached the patch as 2844.patch.txt

For completeness, a couple notes:

  • The documentation section I linked to is for Array/Hash Argument -- so I should mention that I do not think the part mentioning hashes needs updating.
  • The documentation for calling methods seems correct and also does not need updating.
Actions #4

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Status changed from Open to Closed
  • Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED

Updated by naruse (Yui NARUSE) about 4 years ago

  • Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE

ruby_2_7 3c93ed59773ca547239850d16f06451afbb0aeec.

Updated by usa (Usaku NAKAMURA) about 3 years ago

  • Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE to 2.5: REQUIRED, 2.6: DONE, 2.7: DONE

ruby_2_6 r67900 merged revision(s) 3c93ed59.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0