Skip to content

Commit 3717901

Browse files
authored
[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
1 parent dabb6c4 commit 3717901

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

range.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,8 +2438,12 @@ range_overlap(VALUE range, VALUE other)
24382438
* A beginless range may be used to slice an array:
24392439
*
24402440
* a = [1, 2, 3, 4]
2441-
* r = (..2) # => nil...2
2442-
* a[r] # => [1, 2]
2441+
* # Include the third array element in the slice
2442+
* r = (..2) # => nil..2
2443+
* a[r] # => [1, 2, 3]
2444+
* # Exclude the third array element from the slice
2445+
* r = (...2) # => nil...2
2446+
* a[r] # => [1, 2]
24432447
*
24442448
* \Method +each+ for a beginless range raises an exception.
24452449
*

0 commit comments

Comments
 (0)