ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:96917] [Ruby master Bug#16514] Documentation mistake for method syntax (a splat parameter does not need to be at the end)
       [not found] <redmine.issue-16514.20200116204503@ruby-lang.org>
@ 2020-01-16 20:45 ` adam.r.isom
  2020-01-16 21:50 ` [ruby-core:96918] [Ruby master Bug#16514] Documentation mistake for method syntax (splat/array parameter) adam.r.isom
  1 sibling, 0 replies; 2+ messages in thread
From: adam.r.isom @ 2020-01-16 20:45 UTC (permalink / raw)
  To: ruby-core

Issue #16514 has been reported by adamisom (Adam Isom).

----------------------------------------
Bug #16514: Documentation mistake for method syntax (a splat parameter does not need to be at the end)
https://bugs.ruby-lang.org/issues/16514

* Author: adamisom (Adam Isom)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Hello,

In the docs for method definition syntax [here](https://github.com/ruby/ruby/blob/master/doc/syntax/methods.rdoc#arrayhash-argument) we find "The array argument must be the last positional argument".
This is, of course, what is shown on the [ruby-lang.org](https://docs.ruby-lang.org/en/2.7.0/syntax/methods_rdoc.html) and [ruby-doc.org](https://ruby-doc.org/core-2.7.0/doc/syntax/methods_rdoc.html) pages on method syntax.

This is not true. Example code (2.7)

``` ruby
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



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:96918] [Ruby master Bug#16514] Documentation mistake for method syntax (splat/array parameter)
       [not found] <redmine.issue-16514.20200116204503@ruby-lang.org>
  2020-01-16 20:45 ` [ruby-core:96917] [Ruby master Bug#16514] Documentation mistake for method syntax (a splat parameter does not need to be at the end) adam.r.isom
@ 2020-01-16 21:50 ` adam.r.isom
  1 sibling, 0 replies; 2+ messages in thread
From: adam.r.isom @ 2020-01-16 21:50 UTC (permalink / raw)
  To: ruby-core

Issue #16514 has been updated by adamisom (Adam Isom).


I've submitted Github pull request 2844 [here](https://github.com/ruby/ruby/pull/2844)

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 hash section needs updating. 
* The [documentation for *calling* methods](https://ruby-doc.org/core-2.7.0/doc/syntax/calling_methods_rdoc.html) seems correct and also does not need updating. 

----------------------------------------
Bug #16514: Documentation mistake for method syntax (splat/array parameter)
https://bugs.ruby-lang.org/issues/16514#change-83936

* Author: adamisom (Adam Isom)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Hello,

In the docs for method definition syntax [here](https://github.com/ruby/ruby/blob/master/doc/syntax/methods.rdoc#arrayhash-argument) we find "The array argument must be the last positional argument".
This is, of course, what is shown on the [ruby-lang.org](https://docs.ruby-lang.org/en/2.7.0/syntax/methods_rdoc.html) and [ruby-doc.org](https://ruby-doc.org/core-2.7.0/doc/syntax/methods_rdoc.html) pages on method syntax.

This is not true. Example code (2.7)

``` ruby
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



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-16 21:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16514.20200116204503@ruby-lang.org>
2020-01-16 20:45 ` [ruby-core:96917] [Ruby master Bug#16514] Documentation mistake for method syntax (a splat parameter does not need to be at the end) adam.r.isom
2020-01-16 21:50 ` [ruby-core:96918] [Ruby master Bug#16514] Documentation mistake for method syntax (splat/array parameter) adam.r.isom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).