|
13 | 13 | # * Index 1 indicates the second element. |
14 | 14 | # * ... |
15 | 15 | # |
16 | | -# |
17 | 16 | # A negative index is an offset, backwards, from the end of the array: |
18 | 17 | # |
19 | 18 | # * Index -1 indicates the last element. |
20 | 19 | # * Index -2 indicates the next-to-last element. |
21 | 20 | # * ... |
22 | 21 | # |
23 | | -# |
24 | 22 | # A non-negative index is *in range* if and only if it is smaller than the size |
25 | 23 | # of the array. For a 3-element array: |
26 | 24 | # |
27 | 25 | # * Indexes 0 through 2 are in range. |
28 | 26 | # * Index 3 is out of range. |
29 | 27 | # |
30 | | -# |
31 | 28 | # A negative index is *in range* if and only if its absolute value is not larger |
32 | 29 | # than the size of the array. For a 3-element array: |
33 | 30 | # |
34 | 31 | # * Indexes -1 through -3 are in range. |
35 | 32 | # * Index -4 is out of range. |
36 | 33 | # |
37 | | -# |
38 | 34 | # Although the effective index into an array is always an integer, some methods |
39 | 35 | # (both within and outside of class Array) accept one or more non-integer |
40 | 36 | # arguments that are [integer-convertible |
|
91 | 87 | # Array.new(3) {Array.new(3)} |
92 | 88 | # # => [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil]] |
93 | 89 | # |
94 | | -# |
95 | 90 | # A number of Ruby methods, both in the core and in the standard library, |
96 | 91 | # provide instance method `to_a`, which converts an object to an array. |
97 | 92 | # |
|
122 | 117 | # * RubyVM::InstructionSequence#to_a |
123 | 118 | # * YAML::DBM#to_a |
124 | 119 | # |
125 | | -# |
126 | 120 | # ## Example Usage |
127 | 121 | # |
128 | 122 | # In addition to the methods it mixes in through the Enumerable module, the |
|
320 | 314 | # * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which |
321 | 315 | # provides dozens of additional methods. |
322 | 316 | # |
323 | | -# |
324 | 317 | # Here, class Array provides methods that are useful for: |
325 | 318 | # |
326 | 319 | # * [Creating an Array](rdoc-ref:Array@Methods+for+Creating+an+Array) |
|
334 | 327 | # * [Converting](rdoc-ref:Array@Methods+for+Converting) |
335 | 328 | # * [And more....](rdoc-ref:Array@Other+Methods) |
336 | 329 | # |
337 | | -# |
338 | 330 | # ### Methods for Creating an Array |
339 | 331 | # |
340 | 332 | # * ::[]: Returns a new array populated with given objects. |
341 | 333 | # * ::new: Returns a new array. |
342 | 334 | # * ::try_convert: Returns a new array created from a given object. |
343 | 335 | # |
344 | | -# |
345 | 336 | # ### Methods for Querying |
346 | 337 | # |
347 | 338 | # * #length, #size: Returns the count of elements. |
|
358 | 349 | # criterion. |
359 | 350 | # * #hash: Returns the integer hash code. |
360 | 351 | # |
361 | | -# |
362 | 352 | # ### Methods for Comparing |
363 | 353 | # |
364 | 354 | # * #<=>: Returns -1, 0, or 1 * as `self` is less than, equal to, or greater |
|
368 | 358 | # * #eql?: Returns whether each element in `self` is `eql?` to the |
369 | 359 | # corresponding element in a given object. |
370 | 360 | # |
371 | | -# |
372 | 361 | # ### Methods for Fetching |
373 | 362 | # |
374 | 363 | # These methods do not modify `self`. |
|
411 | 400 | # * #sample: Returns one or more random elements. |
412 | 401 | # * #shuffle: Returns elements in a random order. |
413 | 402 | # |
414 | | -# |
415 | 403 | # ### Methods for Assigning |
416 | 404 | # |
417 | 405 | # These methods add, replace, or reorder elements in `self`. |
|
433 | 421 | # * #sort_by!: Replaces `self` with its elements sorted, as determined by a |
434 | 422 | # given block. |
435 | 423 | # |
436 | | -# |
437 | 424 | # ### Methods for Deleting |
438 | 425 | # |
439 | 426 | # Each of these methods removes elements from `self`: |
|
450 | 437 | # * #slice!: Removes and returns a sequence of elements. |
451 | 438 | # * #uniq!: Removes duplicates. |
452 | 439 | # |
453 | | -# |
454 | 440 | # ### Methods for Combining |
455 | 441 | # |
456 | 442 | # * #&: Returns an array containing elements found both in `self` and a given |
|
470 | 456 | # * #product: Returns or yields all combinations of elements from `self` and |
471 | 457 | # given arrays. |
472 | 458 | # |
473 | | -# |
474 | 459 | # ### Methods for Iterating |
475 | 460 | # |
476 | 461 | # * #each: Passes each element to a given block. |
|
487 | 472 | # * #repeated_permutation: Calls a given block with permutations of elements |
488 | 473 | # of `self`; a permutation may use the same element more than once. |
489 | 474 | # |
490 | | -# |
491 | 475 | # ### Methods for Converting |
492 | 476 | # |
493 | 477 | # * #map, #collect: Returns an array containing the block return-value for |
|
506 | 490 | # * #zip: Returns a new array of arrays containing `self` and given arrays; |
507 | 491 | # follow the link for details. |
508 | 492 | # |
509 | | -# |
510 | 493 | # ### Other Methods |
511 | 494 | # |
512 | 495 | # * #*: Returns one of the following: |
|
516 | 499 | # * With string argument `field_separator`, a new string that is |
517 | 500 | # equivalent to `join(field_separator)`. |
518 | 501 | # |
519 | | -# |
520 | 502 | # * #abbrev: Returns a hash of unambiguous abbreviations for elements. |
521 | 503 | # * #pack: Packs the elements into a binary sequence. |
522 | 504 | # * #sum: Returns a sum of elements according to either `+` or a given block. |
@@ -1952,7 +1934,6 @@ class Array[unchecked out Elem] < Object |
1952 | 1934 | # * Each non-Array element is unchanged. |
1953 | 1935 | # * Each Array is replaced by its individual elements. |
1954 | 1936 | # |
1955 | | - # |
1956 | 1937 | # With non-negative Integer argument `level`, flattens recursively through |
1957 | 1938 | # `level` levels: |
1958 | 1939 | # |
@@ -2168,7 +2149,6 @@ class Array[unchecked out Elem] < Object |
2168 | 2149 | # * Uses recursive `element.join(separator)` if `element` is a |
2169 | 2150 | # `kind_of?(Array)`. |
2170 | 2151 | # |
2171 | | - # |
2172 | 2152 | # With no argument, joins using the output field separator, `$,`: |
2173 | 2153 | # |
2174 | 2154 | # a = [:foo, 'bar', 2] |
@@ -2292,7 +2272,6 @@ class Array[unchecked out Elem] < Object |
2292 | 2272 | # * The maximum-valued element from `self`. |
2293 | 2273 | # * A new Array of maximum-valued elements selected from `self`. |
2294 | 2274 | # |
2295 | | - # |
2296 | 2275 | # When no block is given, each element in `self` must respond to method `<=>` |
2297 | 2276 | # with an Integer. |
2298 | 2277 | # |
@@ -2336,7 +2315,6 @@ class Array[unchecked out Elem] < Object |
2336 | 2315 | # * The minimum-valued element from `self`. |
2337 | 2316 | # * A new Array of minimum-valued elements selected from `self`. |
2338 | 2317 | # |
2339 | | - # |
2340 | 2318 | # When no block is given, each element in `self` must respond to method `<=>` |
2341 | 2319 | # with an Integer. |
2342 | 2320 | # |
@@ -2606,7 +2584,6 @@ class Array[unchecked out Elem] < Object |
2606 | 2584 | # including both `self` and `other_arrays`. |
2607 | 2585 | # * The order of the returned combinations is indeterminate. |
2608 | 2586 | # |
2609 | | - # |
2610 | 2587 | # When no block is given, returns the combinations as an Array of Arrays: |
2611 | 2588 | # |
2612 | 2589 | # a = [0, 1, 2] |
@@ -3416,7 +3393,6 @@ class Array[unchecked out Elem] < Object |
3416 | 3393 | # * Zero when `a` and `b` are equivalent. |
3417 | 3394 | # * Positive when `a` is to follow `b`. |
3418 | 3395 | # |
3419 | | - # |
3420 | 3396 | # Example: |
3421 | 3397 | # |
3422 | 3398 | # a = 'abcde'.split('').shuffle |
@@ -3460,7 +3436,6 @@ class Array[unchecked out Elem] < Object |
3460 | 3436 | # * Zero when `a` and `b` are equivalent. |
3461 | 3437 | # * Positive when `a` is to follow `b`. |
3462 | 3438 | # |
3463 | | - # |
3464 | 3439 | # Example: |
3465 | 3440 | # |
3466 | 3441 | # a = 'abcde'.split('').shuffle |
@@ -3811,7 +3786,6 @@ class Array[unchecked out Elem] < Object |
3811 | 3786 | # * The *nth* element of `self`. |
3812 | 3787 | # * The *nth* element of each of the `other_arrays`. |
3813 | 3788 | # |
3814 | | - # |
3815 | 3789 | # If all `other_arrays` and `self` are the same size: |
3816 | 3790 | # |
3817 | 3791 | # a = [:a0, :a1, :a2, :a3] |
|
0 commit comments