mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[DOC] Fix and improve array slicing example in range.c
* [DOC] Fix typo in range.c In the example of the beginless range used for array slicing, '..' range literal was used while the '...' literal was expected * [DOC] Add example for array slicing in range.c Add an example for the array slice with the beginless range using the '..' range literal * [DOC] Add comments for array slicing in range.c Add comments to make crystal clear what the '..' and '...' range literals do when used for array slicing as beginless range
This commit is contained in:
parent
dabb6c49aa
commit
371790165f
Notes:
git
2024-07-17 02:42:47 +00:00
Merged: https://github.com/ruby/ruby/pull/11150 Merged-By: nobu <nobu@ruby-lang.org>
1 changed files with 6 additions and 2 deletions
8
range.c
8
range.c
|
@ -2438,8 +2438,12 @@ range_overlap(VALUE range, VALUE other)
|
|||
* A beginless range may be used to slice an array:
|
||||
*
|
||||
* a = [1, 2, 3, 4]
|
||||
* r = (..2) # => nil...2
|
||||
* a[r] # => [1, 2]
|
||||
* # Include the third array element in the slice
|
||||
* r = (..2) # => nil..2
|
||||
* a[r] # => [1, 2, 3]
|
||||
* # Exclude the third array element from the slice
|
||||
* r = (...2) # => nil...2
|
||||
* a[r] # => [1, 2]
|
||||
*
|
||||
* \Method +each+ for a beginless range raises an exception.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue