rbs 3.0.0.dev.2 → 3.0.0.dev.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -1
  3. data/.github/workflows/ruby.yml +4 -0
  4. data/Gemfile.lock +11 -11
  5. data/Rakefile +2 -2
  6. data/Steepfile +1 -1
  7. data/core/array.rbs +573 -423
  8. data/core/basic_object.rbs +11 -39
  9. data/core/binding.rbs +1 -1
  10. data/core/builtin.rbs +8 -0
  11. data/core/class.rbs +37 -0
  12. data/core/comparable.rbs +7 -18
  13. data/core/complex.rbs +2 -2
  14. data/core/data.rbs +419 -0
  15. data/core/dir.rbs +52 -104
  16. data/core/encoding.rbs +22 -181
  17. data/core/enumerable.rbs +212 -175
  18. data/core/enumerator/product.rbs +96 -0
  19. data/core/enumerator.rbs +57 -8
  20. data/core/errors.rbs +8 -2
  21. data/core/exception.rbs +41 -0
  22. data/core/fiber.rbs +95 -12
  23. data/core/file.rbs +840 -275
  24. data/core/file_test.rbs +34 -19
  25. data/core/float.rbs +40 -96
  26. data/core/gc.rbs +15 -3
  27. data/core/hash.rbs +113 -175
  28. data/core/integer.rbs +85 -145
  29. data/core/io/buffer.rbs +187 -60
  30. data/core/io/wait.rbs +28 -16
  31. data/core/io.rbs +1859 -1389
  32. data/core/kernel.rbs +525 -961
  33. data/core/match_data.rbs +306 -142
  34. data/core/math.rbs +506 -234
  35. data/core/method.rbs +0 -24
  36. data/core/module.rbs +110 -17
  37. data/core/nil_class.rbs +2 -0
  38. data/core/numeric.rbs +76 -144
  39. data/core/object.rbs +88 -212
  40. data/core/proc.rbs +17 -5
  41. data/core/process.rbs +22 -5
  42. data/core/ractor.rbs +1 -1
  43. data/core/random.rbs +20 -3
  44. data/core/range.rbs +91 -89
  45. data/core/rational.rbs +2 -3
  46. data/core/rbs/unnamed/argf.rbs +177 -120
  47. data/core/rbs/unnamed/env_class.rbs +89 -163
  48. data/core/rbs/unnamed/random.rbs +36 -12
  49. data/core/refinement.rbs +8 -0
  50. data/core/regexp.rbs +462 -272
  51. data/core/ruby_vm.rbs +210 -0
  52. data/{stdlib/set/0 → core}/set.rbs +43 -47
  53. data/core/string.rbs +1403 -1332
  54. data/core/string_io.rbs +191 -107
  55. data/core/struct.rbs +67 -63
  56. data/core/symbol.rbs +187 -201
  57. data/core/thread.rbs +40 -35
  58. data/core/time.rbs +902 -826
  59. data/core/trace_point.rbs +55 -6
  60. data/core/unbound_method.rbs +48 -24
  61. data/docs/collection.md +4 -0
  62. data/docs/syntax.md +55 -0
  63. data/ext/rbs_extension/parser.c +5 -6
  64. data/lib/rbs/cli.rb +6 -1
  65. data/lib/rbs/collection/cleaner.rb +8 -1
  66. data/lib/rbs/collection/config/lockfile.rb +3 -1
  67. data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
  68. data/lib/rbs/collection/config.rb +1 -1
  69. data/lib/rbs/collection/sources/git.rb +9 -2
  70. data/lib/rbs/collection/sources/local.rb +79 -0
  71. data/lib/rbs/collection/sources.rb +8 -1
  72. data/lib/rbs/environment.rb +6 -5
  73. data/lib/rbs/environment_loader.rb +3 -2
  74. data/lib/rbs/errors.rb +18 -0
  75. data/lib/rbs/locator.rb +26 -7
  76. data/lib/rbs/sorter.rb +2 -2
  77. data/lib/rbs/version.rb +1 -1
  78. data/sig/collection/sources.rbs +32 -3
  79. data/sig/environment.rbs +2 -3
  80. data/sig/locator.rbs +14 -2
  81. data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
  82. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
  83. data/stdlib/cgi/0/core.rbs +16 -0
  84. data/stdlib/coverage/0/coverage.rbs +50 -8
  85. data/stdlib/csv/0/csv.rbs +1 -1
  86. data/stdlib/date/0/date.rbs +856 -726
  87. data/stdlib/date/0/date_time.rbs +83 -210
  88. data/stdlib/erb/0/erb.rbs +13 -36
  89. data/stdlib/etc/0/etc.rbs +127 -20
  90. data/stdlib/fileutils/0/fileutils.rbs +1290 -381
  91. data/stdlib/logger/0/logger.rbs +466 -316
  92. data/stdlib/net-http/0/net-http.rbs +2211 -534
  93. data/stdlib/nkf/0/nkf.rbs +5 -5
  94. data/stdlib/objspace/0/objspace.rbs +31 -14
  95. data/stdlib/openssl/0/openssl.rbs +11 -7
  96. data/stdlib/optparse/0/optparse.rbs +20 -17
  97. data/stdlib/pathname/0/pathname.rbs +21 -4
  98. data/stdlib/pstore/0/pstore.rbs +378 -154
  99. data/stdlib/pty/0/pty.rbs +24 -8
  100. data/stdlib/ripper/0/ripper.rbs +1650 -0
  101. data/stdlib/socket/0/addrinfo.rbs +9 -15
  102. data/stdlib/socket/0/socket.rbs +36 -3
  103. data/stdlib/strscan/0/string_scanner.rbs +7 -5
  104. data/stdlib/tempfile/0/tempfile.rbs +104 -44
  105. data/stdlib/time/0/time.rbs +2 -2
  106. data/stdlib/uri/0/file.rbs +5 -0
  107. data/stdlib/uri/0/generic.rbs +2 -2
  108. data/stdlib/yaml/0/yaml.rbs +2 -2
  109. data/stdlib/zlib/0/zlib.rbs +1 -1
  110. metadata +8 -6
  111. data/core/deprecated.rbs +0 -9
  112. data/sig/shims/ripper.rbs +0 -8
data/core/array.rbs CHANGED
@@ -1,80 +1,127 @@
1
1
  # <!-- rdoc-file=array.c -->
2
2
  # An Array is an ordered, integer-indexed collection of objects, called
3
- # *elements*. Any object may be an Array element.
3
+ # *elements*. Any object (even another array) may be an array element, and an
4
+ # array can contain objects of different types.
4
5
  #
5
6
  # ## Array Indexes
6
7
  #
7
8
  # Array indexing starts at 0, as in C or Java.
8
9
  #
9
10
  # A positive index is an offset from the first element:
11
+ #
10
12
  # * Index 0 indicates the first element.
11
13
  # * Index 1 indicates the second element.
12
14
  # * ...
13
15
  #
14
16
  #
15
17
  # A negative index is an offset, backwards, from the end of the array:
18
+ #
16
19
  # * Index -1 indicates the last element.
17
20
  # * Index -2 indicates the next-to-last element.
18
21
  # * ...
19
22
  #
20
23
  #
21
- # A non-negative index is *in range* if it is smaller than the size of the
22
- # array. For a 3-element array:
24
+ # A non-negative index is *in range* if and only if it is smaller than the size
25
+ # of the array. For a 3-element array:
26
+ #
23
27
  # * Indexes 0 through 2 are in range.
24
28
  # * Index 3 is out of range.
25
29
  #
26
30
  #
27
- # A negative index is *in range* if its absolute value is not larger than the
28
- # size of the array. For a 3-element array:
31
+ # A negative index is *in range* if and only if its absolute value is not larger
32
+ # than the size of the array. For a 3-element array:
33
+ #
29
34
  # * Indexes -1 through -3 are in range.
30
35
  # * Index -4 is out of range.
31
36
  #
32
37
  #
38
+ # Although the effective index into an array is always an integer, some methods
39
+ # (both within and outside of class Array) accept one or more non-integer
40
+ # arguments that are [integer-convertible
41
+ # objects](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
42
+ #
33
43
  # ## Creating Arrays
34
44
  #
35
45
  # You can create an Array object explicitly with:
36
46
  #
37
- # * An [array literal](doc/syntax/literals_rdoc.html#label-Array+Literals).
47
+ # * An [array literal](rdoc-ref:literals.rdoc@Array+Literals):
48
+ #
49
+ # [1, 'one', :one, [2, 'two', :two]]
38
50
  #
51
+ # * A [%w or %W: string-array
52
+ # Literal](rdoc-ref:literals.rdoc@25w+and+-25W-3A+String-Array+Literals):
39
53
  #
40
- # You can convert certain objects to Arrays with:
54
+ # %w[foo bar baz] # => ["foo", "bar", "baz"]
55
+ # %w[1 % *] # => ["1", "%", "*"]
41
56
  #
42
- # * Method [Array](Kernel.html#method-i-Array).
57
+ # * A [%i pr %I: symbol-array
58
+ # Literal](rdoc-ref:literals.rdoc@25i+and+-25I-3A+Symbol-Array+Literals):
43
59
  #
60
+ # %i[foo bar baz] # => [:foo, :bar, :baz]
61
+ # %i[1 % *] # => [:"1", :%, :*]
44
62
  #
45
- # An Array can contain different types of objects. For example, the array below
46
- # contains an Integer, a String and a Float:
63
+ # * Method Kernel#Array:
47
64
  #
48
- # ary = [1, "two", 3.0] #=> [1, "two", 3.0]
65
+ # Array(["a", "b"]) # => ["a", "b"]
66
+ # Array(1..5) # => [1, 2, 3, 4, 5]
67
+ # Array(key: :value) # => [[:key, :value]]
68
+ # Array(nil) # => []
69
+ # Array(1) # => [1]
70
+ # Array({:a => "a", :b => "b"}) # => [[:a, "a"], [:b, "b"]]
49
71
  #
50
- # An array can also be created by calling Array.new with zero, one (the initial
51
- # size of the Array) or two arguments (the initial size and a default object).
72
+ # * Method Array.new:
52
73
  #
53
- # ary = Array.new #=> []
54
- # Array.new(3) #=> [nil, nil, nil]
55
- # Array.new(3, true) #=> [true, true, true]
74
+ # Array.new # => []
75
+ # Array.new(3) # => [nil, nil, nil]
76
+ # Array.new(4) {Hash.new} # => [{}, {}, {}, {}]
77
+ # Array.new(3, true) # => [true, true, true]
56
78
  #
57
- # Note that the second argument populates the array with references to the same
58
- # object. Therefore, it is only recommended in cases when you need to
59
- # instantiate arrays with natively immutable objects such as Symbols, numbers,
60
- # true or false.
79
+ # Note that the last example above populates the array with references to
80
+ # the same object. This is recommended only in cases where that object is a
81
+ # natively immutable object such as a symbol, a numeric, `nil`, `true`, or
82
+ # `false`.
61
83
  #
62
- # To create an array with separate objects a block can be passed instead. This
63
- # method is safe to use with mutable objects such as hashes, strings or other
64
- # arrays:
84
+ # Another way to create an array with various objects, using a block; this
85
+ # usage is safe for mutable objects such as hashes, strings or other arrays:
65
86
  #
66
- # Array.new(4) {Hash.new} #=> [{}, {}, {}, {}]
67
- # Array.new(4) {|i| i.to_s } #=> ["0", "1", "2", "3"]
87
+ # Array.new(4) {|i| i.to_s } # => ["0", "1", "2", "3"]
68
88
  #
69
- # This is also a quick way to build up multi-dimensional arrays:
89
+ # Here is a way to create a multi-dimensional array:
70
90
  #
71
- # empty_table = Array.new(3) {Array.new(3)}
72
- # #=> [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil]]
91
+ # Array.new(3) {Array.new(3)}
92
+ # # => [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil]]
73
93
  #
74
- # An array can also be created by using the Array() method, provided by Kernel,
75
- # which tries to call #to_ary, then #to_a on its argument.
76
94
  #
77
- # Array({:a => "a", :b => "b"}) #=> [[:a, "a"], [:b, "b"]]
95
+ # A number of Ruby methods, both in the core and in the standard library,
96
+ # provide instance method `to_a`, which converts an object to an array.
97
+ #
98
+ # * ARGF#to_a
99
+ # * Array#to_a
100
+ # * Enumerable#to_a
101
+ # * Hash#to_a
102
+ # * MatchData#to_a
103
+ # * NilClass#to_a
104
+ # * OptionParser#to_a
105
+ # * Range#to_a
106
+ # * Set#to_a
107
+ # * Struct#to_a
108
+ # * Time#to_a
109
+ # * Benchmark::Tms#to_a
110
+ # * CSV::Table#to_a
111
+ # * Enumerator::Lazy#to_a
112
+ # * Gem::List#to_a
113
+ # * Gem::NameTuple#to_a
114
+ # * Gem::Platform#to_a
115
+ # * Gem::RequestSet::Lockfile::Tokenizer#to_a
116
+ # * Gem::SourceList#to_a
117
+ # * OpenSSL::X509::Extension#to_a
118
+ # * OpenSSL::X509::Name#to_a
119
+ # * Racc::ISet#to_a
120
+ # * Rinda::RingFinger#to_a
121
+ # * Ripper::Lexer::Elem#to_a
122
+ # * RubyVM::InstructionSequence#to_a
123
+ # * YAML::DBM#to_a
124
+ #
78
125
  #
79
126
  # ## Example Usage
80
127
  #
@@ -269,298 +316,210 @@
269
316
  #
270
317
  # First, what's elsewhere. Class Array:
271
318
  #
272
- # * Inherits from [class
273
- # Object](Object.html#class-Object-label-What-27s+Here).
274
- # * Includes [module
275
- # Enumerable](Enumerable.html#module-Enumerable-label-What-27s+Here), which
319
+ # * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
320
+ # * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
276
321
  # provides dozens of additional methods.
277
322
  #
278
323
  #
279
324
  # Here, class Array provides methods that are useful for:
280
325
  #
281
- # * [Creating an Array](#class-Array-label-Methods+for+Creating+an+Array)
282
- # * [Querying](#class-Array-label-Methods+for+Querying)
283
- # * [Comparing](#class-Array-label-Methods+for+Comparing)
284
- # * [Fetching](#class-Array-label-Methods+for+Fetching)
285
- # * [Assigning](#class-Array-label-Methods+for+Assigning)
286
- # * [Deleting](#class-Array-label-Methods+for+Deleting)
287
- # * [Combining](#class-Array-label-Methods+for+Combining)
288
- # * [Iterating](#class-Array-label-Methods+for+Iterating)
289
- # * [Converting](#class-Array-label-Methods+for+Converting)
290
- # * [And more....](#class-Array-label-Other+Methods)
326
+ # * [Creating an Array](rdoc-ref:Array@Methods+for+Creating+an+Array)
327
+ # * [Querying](rdoc-ref:Array@Methods+for+Querying)
328
+ # * [Comparing](rdoc-ref:Array@Methods+for+Comparing)
329
+ # * [Fetching](rdoc-ref:Array@Methods+for+Fetching)
330
+ # * [Assigning](rdoc-ref:Array@Methods+for+Assigning)
331
+ # * [Deleting](rdoc-ref:Array@Methods+for+Deleting)
332
+ # * [Combining](rdoc-ref:Array@Methods+for+Combining)
333
+ # * [Iterating](rdoc-ref:Array@Methods+for+Iterating)
334
+ # * [Converting](rdoc-ref:Array@Methods+for+Converting)
335
+ # * [And more....](rdoc-ref:Array@Other+Methods)
291
336
  #
292
337
  #
293
338
  # ### Methods for Creating an Array
294
339
  #
295
- # ::[]
296
- # : Returns a new array populated with given objects.
297
- # ::new
298
- # : Returns a new array.
299
- # ::try_convert
300
- # : Returns a new array created from a given object.
340
+ # * ::[]: Returns a new array populated with given objects.
341
+ # * ::new: Returns a new array.
342
+ # * ::try_convert: Returns a new array created from a given object.
301
343
  #
302
344
  #
303
345
  # ### Methods for Querying
304
346
  #
305
- # #length, #size
306
- # : Returns the count of elements.
307
- # #include?
308
- # : Returns whether any element `==` a given object.
309
- # #empty?
310
- # : Returns whether there are no elements.
311
- # #all?
312
- # : Returns whether all elements meet a given criterion.
313
- # #any?
314
- # : Returns whether any element meets a given criterion.
315
- # #none?
316
- # : Returns whether no element `==` a given object.
317
- # #one?
318
- # : Returns whether exactly one element `==` a given object.
319
- # #count
320
- # : Returns the count of elements that meet a given criterion.
321
- # #find_index, #index
322
- # : Returns the index of the first element that meets a given criterion.
323
- # #rindex
324
- # : Returns the index of the last element that meets a given criterion.
325
- # #hash
326
- # : Returns the integer hash code.
347
+ # * #length, #size: Returns the count of elements.
348
+ # * #include?: Returns whether any element `==` a given object.
349
+ # * #empty?: Returns whether there are no elements.
350
+ # * #all?: Returns whether all elements meet a given criterion.
351
+ # * #any?: Returns whether any element meets a given criterion.
352
+ # * #none?: Returns whether no element `==` a given object.
353
+ # * #one?: Returns whether exactly one element `==` a given object.
354
+ # * #count: Returns the count of elements that meet a given criterion.
355
+ # * #find_index, #index: Returns the index of the first element that meets a
356
+ # given criterion.
357
+ # * #rindex: Returns the index of the last element that meets a given
358
+ # criterion.
359
+ # * #hash: Returns the integer hash code.
327
360
  #
328
361
  #
329
362
  # ### Methods for Comparing
330
- # [#<=>](#method-i-3C-3D-3E)
331
- # : Returns -1, 0, or 1 as `self` is less than, equal to, or greater than a
332
- # given object.
333
- # [#==](#method-i-3D-3D)
334
- # : Returns whether each element in `self` is `==` to the corresponding
335
- # element in a given object.
336
- # #eql?
337
- # : Returns whether each element in `self` is `eql?` to the corresponding
363
+ #
364
+ # * #<=>: Returns -1, 0, or 1 * as `self` is less than, equal to, or greater
365
+ # than a given object.
366
+ # * #==: Returns whether each element in `self` is `==` to the corresponding
338
367
  # element in a given object.
368
+ # * #eql?: Returns whether each element in `self` is `eql?` to the
369
+ # corresponding element in a given object.
339
370
  #
340
371
  #
341
372
  # ### Methods for Fetching
342
373
  #
343
374
  # These methods do not modify `self`.
344
375
  #
345
- # #[]
346
- # : Returns one or more elements.
347
- # #fetch
348
- # : Returns the element at a given offset.
349
- # #first
350
- # : Returns one or more leading elements.
351
- # #last
352
- # : Returns one or more trailing elements.
353
- # #max
354
- # : Returns one or more maximum-valued elements, as determined by `<=>` or a
355
- # given block.
356
- # #max
357
- # : Returns one or more minimum-valued elements, as determined by `<=>` or a
358
- # given block.
359
- # #minmax
360
- # : Returns the minimum-valued and maximum-valued elements, as determined by
361
- # `<=>` or a given block.
362
- # #assoc
363
- # : Returns the first element that is an array whose first element `==` a
364
- # given object.
365
- # #rassoc
366
- # : Returns the first element that is an array whose second element `==` a
367
- # given object.
368
- # #at
369
- # : Returns the element at a given offset.
370
- # #values_at
371
- # : Returns the elements at given offsets.
372
- # #dig
373
- # : Returns the object in nested objects that is specified by a given index
374
- # and additional arguments.
375
- # #drop
376
- # : Returns trailing elements as determined by a given index.
377
- # #take
378
- # : Returns leading elements as determined by a given index.
379
- # #drop_while
380
- # : Returns trailing elements as determined by a given block.
381
- # #take_while
382
- # : Returns leading elements as determined by a given block.
383
- # #slice
384
- # : Returns consecutive elements as determined by a given argument.
385
- # #sort
386
- # : Returns all elements in an order determined by `<=>` or a given block.
387
- # #reverse
388
- # : Returns all elements in reverse order.
389
- # #compact
390
- # : Returns an array containing all non-`nil` elements.
391
- # #select, #filter
392
- # : Returns an array containing elements selected by a given block.
393
- # #uniq
394
- # : Returns an array containing non-duplicate elements.
395
- # #rotate
396
- # : Returns all elements with some rotated from one end to the other.
397
- # #bsearch
398
- # : Returns an element selected via a binary search as determined by a given
376
+ # * #[]: Returns one or more elements.
377
+ # * #fetch: Returns the element at a given offset.
378
+ # * #first: Returns one or more leading elements.
379
+ # * #last: Returns one or more trailing elements.
380
+ # * #max: Returns one or more maximum-valued elements, as determined by `<=>`
381
+ # or a given block.
382
+ # * #min: Returns one or more minimum-valued elements, as determined by `<=>`
383
+ # or a given block.
384
+ # * #minmax: Returns the minimum-valued and maximum-valued elements, as
385
+ # determined by `<=>` or a given block.
386
+ # * #assoc: Returns the first element that is an array whose first element
387
+ # `==` a given object.
388
+ # * #rassoc: Returns the first element that is an array whose second element
389
+ # `==` a given object.
390
+ # * #at: Returns the element at a given offset.
391
+ # * #values_at: Returns the elements at given offsets.
392
+ # * #dig: Returns the object in nested objects that is specified by a given
393
+ # index and additional arguments.
394
+ # * #drop: Returns trailing elements as determined by a given index.
395
+ # * #take: Returns leading elements as determined by a given index.
396
+ # * #drop_while: Returns trailing elements as determined by a given block.
397
+ # * #take_while: Returns leading elements as determined by a given block.
398
+ # * #slice: Returns consecutive elements as determined by a given argument.
399
+ # * #sort: Returns all elements in an order determined by `<=>` or a given
400
+ # block.
401
+ # * #reverse: Returns all elements in reverse order.
402
+ # * #compact: Returns an array containing all non-`nil` elements.
403
+ # * #select, #filter: Returns an array containing elements selected by a given
399
404
  # block.
400
- # #bsearch_index
401
- # : Returns the index of an element selected via a binary search as determined
402
- # by a given block.
403
- # #sample
404
- # : Returns one or more random elements.
405
- # #shuffle
406
- # : Returns elements in a random order.
405
+ # * #uniq: Returns an array containing non-duplicate elements.
406
+ # * #rotate: Returns all elements with some rotated from one end to the other.
407
+ # * #bsearch: Returns an element selected via a binary search as determined by
408
+ # a given block.
409
+ # * #bsearch_index: Returns the index of an element selected via a binary
410
+ # search as determined by a given block.
411
+ # * #sample: Returns one or more random elements.
412
+ # * #shuffle: Returns elements in a random order.
407
413
  #
408
414
  #
409
415
  # ### Methods for Assigning
410
416
  #
411
417
  # These methods add, replace, or reorder elements in `self`.
412
418
  #
413
- # #[]=
414
- # : Assigns specified elements with a given object.
415
- # #push, #append, #<<
416
- # : Appends trailing elements.
417
- # #unshift, #prepend
418
- # : Prepends leading elements.
419
- # #insert
420
- # : Inserts given objects at a given offset; does not replace elements.
421
- # #concat
422
- # : Appends all elements from given arrays.
423
- # #fill
424
- # : Replaces specified elements with specified objects.
425
- # #replace
426
- # : Replaces the content of `self` with the content of a given array.
427
- # #reverse!
428
- # : Replaces `self` with its elements reversed.
429
- # #rotate!
430
- # : Replaces `self` with its elements rotated.
431
- # #shuffle!
432
- # : Replaces `self` with its elements in random order.
433
- # #sort!
434
- # : Replaces `self` with its elements sorted, as determined by `<=>` or a
419
+ # * #[]=: Assigns specified elements with a given object.
420
+ # * #push, #append, #<<: Appends trailing elements.
421
+ # * #unshift, #prepend: Prepends leading elements.
422
+ # * #insert: Inserts given objects at a given offset; does not replace
423
+ # elements.
424
+ # * #concat: Appends all elements from given arrays.
425
+ # * #fill: Replaces specified elements with specified objects.
426
+ # * #replace: Replaces the content of `self` with the content of a given
427
+ # array.
428
+ # * #reverse!: Replaces `self` with its elements reversed.
429
+ # * #rotate!: Replaces `self` with its elements rotated.
430
+ # * #shuffle!: Replaces `self` with its elements in random order.
431
+ # * #sort!: Replaces `self` with its elements sorted, as determined by `<=>`
432
+ # or a given block.
433
+ # * #sort_by!: Replaces `self` with its elements sorted, as determined by a
435
434
  # given block.
436
- # #sort_by!
437
- # : Replaces `self` with its elements sorted, as determined by a given block.
438
435
  #
439
436
  #
440
437
  # ### Methods for Deleting
441
438
  #
442
439
  # Each of these methods removes elements from `self`:
443
440
  #
444
- # #pop
445
- # : Removes and returns the last element.
446
- # #shift
447
- # : Removes and returns the first element.
448
- # #compact!
449
- # : Removes all non-`nil` elements.
450
- # #delete
451
- # : Removes elements equal to a given object.
452
- # #delete_at
453
- # : Removes the element at a given offset.
454
- # #delete_if
455
- # : Removes elements specified by a given block.
456
- # #keep_if
457
- # : Removes elements not specified by a given block.
458
- # #reject!
459
- # : Removes elements specified by a given block.
460
- # #select!, #filter!
461
- # : Removes elements not specified by a given block.
462
- # #slice!
463
- # : Removes and returns a sequence of elements.
464
- # #uniq!
465
- # : Removes duplicates.
441
+ # * #pop: Removes and returns the last element.
442
+ # * #shift: Removes and returns the first element.
443
+ # * #compact!: Removes all `nil` elements.
444
+ # * #delete: Removes elements equal to a given object.
445
+ # * #delete_at: Removes the element at a given offset.
446
+ # * #delete_if: Removes elements specified by a given block.
447
+ # * #keep_if: Removes elements not specified by a given block.
448
+ # * #reject!: Removes elements specified by a given block.
449
+ # * #select!, #filter!: Removes elements not specified by a given block.
450
+ # * #slice!: Removes and returns a sequence of elements.
451
+ # * #uniq!: Removes duplicates.
466
452
  #
467
453
  #
468
454
  # ### Methods for Combining
469
455
  #
470
- # [#&](#method-i-26)
471
- # : Returns an array containing elements found both in `self` and a given
456
+ # * #&: Returns an array containing elements found both in `self` and a given
472
457
  # array.
473
- # #intersection
474
- # : Returns an array containing elements found both in `self` and in each
475
- # given array.
476
- # #+
477
- # : Returns an array containing all elements of `self` followed by all
458
+ # * #intersection: Returns an array containing elements found both in `self`
459
+ # and in each given array.
460
+ # * #+: Returns an array containing all elements of `self` followed by all
478
461
  # elements of a given array.
479
- # #-
480
- # : Returns an array containiing all elements of `self` that are not found in
481
- # a given array.
482
- # [#|](#method-i-7C)
483
- # : Returns an array containing all elements of `self` and all elements of a
484
- # given array, duplicates removed.
485
- # #union
486
- # : Returns an array containing all elements of `self` and all elements of
487
- # given arrays, duplicates removed.
488
- # #difference
489
- # : Returns an array containing all elements of `self` that are not found in
490
- # any of the given arrays..
491
- # #product
492
- # : Returns or yields all combinations of elements from `self` and given
493
- # arrays.
462
+ # * #-: Returns an array containing all elements of `self` that are not found
463
+ # in a given array.
464
+ # * #|: Returns an array containing all elements of `self` and all elements of
465
+ # a given array, duplicates removed.
466
+ # * #union: Returns an array containing all elements of `self` and all
467
+ # elements of given arrays, duplicates removed.
468
+ # * #difference: Returns an array containing all elements of `self` that are
469
+ # not found in any of the given arrays..
470
+ # * #product: Returns or yields all combinations of elements from `self` and
471
+ # given arrays.
494
472
  #
495
473
  #
496
474
  # ### Methods for Iterating
497
475
  #
498
- # #each
499
- # : Passes each element to a given block.
500
- # #reverse_each
501
- # : Passes each element, in reverse order, to a given block.
502
- # #each_index
503
- # : Passes each element index to a given block.
504
- # #cycle
505
- # : Calls a given block with each element, then does so again, for a specified
506
- # number of times, or forever.
507
- # #combination
508
- # : Calls a given block with combinations of elements of `self`; a combination
509
- # does not use the same element more than once.
510
- # #permutation
511
- # : Calls a given block with permutations of elements of `self`; a permutation
512
- # does not use the same element more than once.
513
- # #repeated_combination
514
- # : Calls a given block with combinations of elements of `self`; a combination
515
- # may use the same element more than once.
516
- # #repeated_permutation
517
- # : Calls a given block with permutations of elements of `self`; a permutation
518
- # may use the same element more than once.
476
+ # * #each: Passes each element to a given block.
477
+ # * #reverse_each: Passes each element, in reverse order, to a given block.
478
+ # * #each_index: Passes each element index to a given block.
479
+ # * #cycle: Calls a given block with each element, then does so again, for a
480
+ # specified number of times, or forever.
481
+ # * #combination: Calls a given block with combinations of elements of `self`;
482
+ # a combination does not use the same element more than once.
483
+ # * #permutation: Calls a given block with permutations of elements of `self`;
484
+ # a permutation does not use the same element more than once.
485
+ # * #repeated_combination: Calls a given block with combinations of elements
486
+ # of `self`; a combination may use the same element more than once.
487
+ # * #repeated_permutation: Calls a given block with permutations of elements
488
+ # of `self`; a permutation may use the same element more than once.
519
489
  #
520
490
  #
521
491
  # ### Methods for Converting
522
492
  #
523
- # #map, #collect
524
- # : Returns an array containing the block return-value for each element.
525
- # #map!, #collect!
526
- # : Replaces each element with a block return-value.
527
- # #flatten
528
- # : Returns an array that is a recursive flattening of `self`.
529
- # #flatten!
530
- # : Replaces each nested array in `self` with the elements from that array.
531
- # #inspect, #to_s
532
- # : Returns a new String containing the elements.
533
- # #join
534
- # : Returns a newsString containing the elements joined by the field
493
+ # * #map, #collect: Returns an array containing the block return-value for
494
+ # each element.
495
+ # * #map!, #collect!: Replaces each element with a block return-value.
496
+ # * #flatten: Returns an array that is a recursive flattening of `self`.
497
+ # * #flatten!: Replaces each nested array in `self` with the elements from
498
+ # that array.
499
+ # * #inspect, #to_s: Returns a new String containing the elements.
500
+ # * #join: Returns a newsString containing the elements joined by the field
535
501
  # separator.
536
- # #to_a
537
- # : Returns `self` or a new array containing all elements.
538
- # #to_ary
539
- # : Returns `self`.
540
- # #to_h
541
- # : Returns a new hash formed from the elements.
542
- # #transpose
543
- # : Transposes `self`, which must be an array of arrays.
544
- # #zip
545
- # : Returns a new array of arrays containing `self` and given arrays; follow
546
- # the link for details.
502
+ # * #to_a: Returns `self` or a new array containing all elements.
503
+ # * #to_ary: Returns `self`.
504
+ # * #to_h: Returns a new hash formed from the elements.
505
+ # * #transpose: Transposes `self`, which must be an array of arrays.
506
+ # * #zip: Returns a new array of arrays containing `self` and given arrays;
507
+ # follow the link for details.
547
508
  #
548
509
  #
549
510
  # ### Other Methods
550
511
  #
551
- # #*
552
- # : Returns one of the following:
512
+ # * #*: Returns one of the following:
513
+ #
553
514
  # * With integer argument `n`, a new array that is the concatenation of
554
515
  # `n` copies of `self`.
555
516
  # * With string argument `field_separator`, a new string that is
556
517
  # equivalent to `join(field_separator)`.
557
518
  #
558
- # #abbrev
559
- # : Returns a hash of unambiguous abbreviations for elements.
560
- # #pack
561
- # : Packs the elements into a binary sequence.
562
- # #sum
563
- # : Returns a sum of elements according to either `+` or a given block.
519
+ #
520
+ # * #abbrev: Returns a hash of unambiguous abbreviations for elements.
521
+ # * #pack: Packs the elements into a binary sequence.
522
+ # * #sum: Returns a sum of elements according to either `+` or a given block.
564
523
  #
565
524
  %a{annotate:rdoc:source:from=array.c}
566
525
  class Array[unchecked out Elem] < Object
@@ -580,23 +539,27 @@ class Array[unchecked out Elem] < Object
580
539
  #
581
540
  # With no block and a single Array argument `array`, returns a new Array formed
582
541
  # from `array`:
542
+ #
583
543
  # a = Array.new([:foo, 'bar', 2])
584
544
  # a.class # => Array
585
545
  # a # => [:foo, "bar", 2]
586
546
  #
587
547
  # With no block and a single Integer argument `size`, returns a new Array of the
588
548
  # given size whose elements are all `nil`:
549
+ #
589
550
  # a = Array.new(3)
590
551
  # a # => [nil, nil, nil]
591
552
  #
592
553
  # With no block and arguments `size` and `default_value`, returns an Array of
593
554
  # the given size; each element is that same `default_value`:
555
+ #
594
556
  # a = Array.new(3, 'x')
595
557
  # a # => ['x', 'x', 'x']
596
558
  #
597
559
  # With a block and argument `size`, returns an Array of the given size; the
598
560
  # block is called with each successive integer `index`; the element for that
599
561
  # `index` is the return value from the block:
562
+ #
600
563
  # a = Array.new(3) {|index| "Element #{index}" }
601
564
  # a # => ["Element 0", "Element 1", "Element 2"]
602
565
  #
@@ -645,10 +608,12 @@ class Array[unchecked out Elem] < Object
645
608
  # -->
646
609
  # Returns a new Array containing each element found in both `array` and Array
647
610
  # `other_array`; duplicates are omitted; items are compared using `eql?`:
611
+ #
648
612
  # [0, 1, 2, 3] & [1, 2] # => [1, 2]
649
613
  # [0, 1, 0, 1] & [0, 1] # => [0, 1]
650
614
  #
651
615
  # Preserves order from `array`:
616
+ #
652
617
  # [0, 1, 2] & [3, 2, 1, 0] # => [0, 1, 2]
653
618
  #
654
619
  # Related: Array#intersection.
@@ -662,11 +627,13 @@ class Array[unchecked out Elem] < Object
662
627
  # -->
663
628
  # When non-negative argument Integer `n` is given, returns a new Array built by
664
629
  # concatenating the `n` copies of `self`:
630
+ #
665
631
  # a = ['x', 'y']
666
632
  # a * 3 # => ["x", "y", "x", "y", "x", "y"]
667
633
  #
668
634
  # When String argument `string_separator` is given, equivalent to
669
635
  # `array.join(string_separator)`:
636
+ #
670
637
  # [0, [0, 1], {foo: 0}] * ', ' # => "0, 0, 1, {:foo=>0}"
671
638
  #
672
639
  def *: (string str) -> ::String
@@ -678,6 +645,7 @@ class Array[unchecked out Elem] < Object
678
645
  # -->
679
646
  # Returns a new Array containing all elements of `array` followed by all
680
647
  # elements of `other_array`:
648
+ #
681
649
  # a = [0, 1] + [2, 3]
682
650
  # a # => [0, 1, 2, 3]
683
651
  #
@@ -692,6 +660,7 @@ class Array[unchecked out Elem] < Object
692
660
  # Returns a new Array containing only those elements from `array` that are not
693
661
  # found in Array `other_array`; items are compared using `eql?`; the order from
694
662
  # `array` is preserved:
663
+ #
695
664
  # [0, 1, 1, 2, 1, 1, 3, 1, 1] - [1] # => [0, 2, 3]
696
665
  # [0, 1, 2, 3] - [3, 0] # => [1, 2]
697
666
  # [0, 1, 2] - [4] # => [0, 1, 2]
@@ -705,10 +674,12 @@ class Array[unchecked out Elem] < Object
705
674
  # - array << object -> self
706
675
  # -->
707
676
  # Appends `object` to `self`; returns `self`:
677
+ #
708
678
  # a = [:foo, 'bar', 2]
709
679
  # a << :baz # => [:foo, "bar", 2, :baz]
710
680
  #
711
681
  # Appends `object` as one element, even if it is another Array:
682
+ #
712
683
  # a = [:foo, 'bar', 2]
713
684
  # a1 = a << [3, 4]
714
685
  # a1 # => [:foo, "bar", 2, [3, 4]]
@@ -724,19 +695,25 @@ class Array[unchecked out Elem] < Object
724
695
  # other_array[i]`.
725
696
  #
726
697
  # Returns -1 if any result is -1:
698
+ #
727
699
  # [0, 1, 2] <=> [0, 1, 3] # => -1
728
700
  #
729
701
  # Returns 1 if any result is 1:
702
+ #
730
703
  # [0, 1, 2] <=> [0, 1, 1] # => 1
731
704
  #
732
705
  # When all results are zero:
706
+ #
733
707
  # * Returns -1 if `array` is smaller than `other_array`:
708
+ #
734
709
  # [0, 1, 2] <=> [0, 1, 2, 3] # => -1
735
710
  #
736
711
  # * Returns 1 if `array` is larger than `other_array`:
712
+ #
737
713
  # [0, 1, 2] <=> [0, 1] # => 1
738
714
  #
739
715
  # * Returns 0 if `array` and `other_array` are the same size:
716
+ #
740
717
  # [0, 1, 2] <=> [0, 1, 2] # => 0
741
718
  #
742
719
  def <=>: (untyped) -> ::Integer?
@@ -747,6 +724,7 @@ class Array[unchecked out Elem] < Object
747
724
  # -->
748
725
  # Returns `true` if both `array.size == other_array.size` and for each index `i`
749
726
  # in `array`, `array[i] == other_array[i]`:
727
+ #
750
728
  # a0 = [:foo, 'bar', 2]
751
729
  # a1 = [:foo, 'bar', 2.0]
752
730
  # a1 == a0 # => true
@@ -774,12 +752,14 @@ class Array[unchecked out Elem] < Object
774
752
  #
775
753
  # When a single Integer argument `index` is given, returns the element at offset
776
754
  # `index`:
755
+ #
777
756
  # a = [:foo, 'bar', 2]
778
757
  # a[0] # => :foo
779
758
  # a[2] # => 2
780
759
  # a # => [:foo, "bar", 2]
781
760
  #
782
761
  # If `index` is negative, counts relative to the end of `self`:
762
+ #
783
763
  # a = [:foo, 'bar', 2]
784
764
  # a[-1] # => 2
785
765
  # a[-2] # => "bar"
@@ -788,12 +768,14 @@ class Array[unchecked out Elem] < Object
788
768
  #
789
769
  # When two Integer arguments `start` and `length` are given, returns a new Array
790
770
  # of size `length` containing successive elements beginning at offset `start`:
771
+ #
791
772
  # a = [:foo, 'bar', 2]
792
773
  # a[0, 2] # => [:foo, "bar"]
793
774
  # a[1, 2] # => ["bar", 2]
794
775
  #
795
776
  # If `start + length` is greater than `self.length`, returns all elements from
796
777
  # offset `start` to the end:
778
+ #
797
779
  # a = [:foo, 'bar', 2]
798
780
  # a[0, 4] # => [:foo, "bar", 2]
799
781
  # a[1, 3] # => ["bar", 2]
@@ -805,6 +787,7 @@ class Array[unchecked out Elem] < Object
805
787
  #
806
788
  # When a single Range argument `range` is given, treats `range.min` as `start`
807
789
  # above and `range.size` as `length` above:
790
+ #
808
791
  # a = [:foo, 'bar', 2]
809
792
  # a[0..1] # => [:foo, "bar"]
810
793
  # a[1..2] # => ["bar", 2]
@@ -812,18 +795,21 @@ class Array[unchecked out Elem] < Object
812
795
  # Special case: If `range.start == a.size`, returns a new empty Array.
813
796
  #
814
797
  # If `range.end` is negative, calculates the end index from the end:
798
+ #
815
799
  # a = [:foo, 'bar', 2]
816
800
  # a[0..-1] # => [:foo, "bar", 2]
817
801
  # a[0..-2] # => [:foo, "bar"]
818
802
  # a[0..-3] # => [:foo]
819
803
  #
820
804
  # If `range.start` is negative, calculates the start index from the end:
805
+ #
821
806
  # a = [:foo, 'bar', 2]
822
807
  # a[-1..2] # => [2]
823
808
  # a[-2..2] # => ["bar", 2]
824
809
  # a[-3..2] # => [:foo, "bar", 2]
825
810
  #
826
811
  # If `range.start` is larger than the array size, returns `nil`.
812
+ #
827
813
  # a = [:foo, 'bar', 2]
828
814
  # a[4..1] # => nil
829
815
  # a[4..0] # => nil
@@ -831,11 +817,13 @@ class Array[unchecked out Elem] < Object
831
817
  #
832
818
  # When a single Enumerator::ArithmeticSequence argument `aseq` is given, returns
833
819
  # an Array of elements corresponding to the indexes produced by the sequence.
820
+ #
834
821
  # a = ['--', 'data1', '--', 'data2', '--', 'data3']
835
822
  # a[(1..).step(2)] # => ["data1", "data2", "data3"]
836
823
  #
837
824
  # Unlike slicing with range, if the start or the end of the arithmetic sequence
838
825
  # is larger than array size, throws RangeError.
826
+ #
839
827
  # a = ['--', 'data1', '--', 'data2', '--', 'data3']
840
828
  # a[(1..11).step(2)]
841
829
  # # RangeError (((1..11).step(2)) out of range)
@@ -844,6 +832,7 @@ class Array[unchecked out Elem] < Object
844
832
  #
845
833
  # If given a single argument, and its type is not one of the listed, tries to
846
834
  # convert it to Integer, and raises if it is impossible:
835
+ #
847
836
  # a = [:foo, 'bar', 2]
848
837
  # # Raises TypeError (no implicit conversion of Symbol into Integer):
849
838
  # a[:foo]
@@ -866,16 +855,19 @@ class Array[unchecked out Elem] < Object
866
855
  # `self`.
867
856
  #
868
857
  # If `index` is non-negative, assigns `object` the element at offset `index`:
858
+ #
869
859
  # a = [:foo, 'bar', 2]
870
860
  # a[0] = 'foo' # => "foo"
871
861
  # a # => ["foo", "bar", 2]
872
862
  #
873
863
  # If `index` is greater than `self.length`, extends the array:
864
+ #
874
865
  # a = [:foo, 'bar', 2]
875
866
  # a[7] = 'foo' # => "foo"
876
867
  # a # => [:foo, "bar", 2, nil, nil, nil, nil, "foo"]
877
868
  #
878
869
  # If `index` is negative, counts backwards from the end of the array:
870
+ #
879
871
  # a = [:foo, 'bar', 2]
880
872
  # a[-1] = 'two' # => "two"
881
873
  # a # => [:foo, "bar", "two"]
@@ -883,11 +875,13 @@ class Array[unchecked out Elem] < Object
883
875
  # When Integer arguments `start` and `length` are given and `object` is not an
884
876
  # Array, removes `length - 1` elements beginning at offset `start`, and assigns
885
877
  # `object` at offset `start`:
878
+ #
886
879
  # a = [:foo, 'bar', 2]
887
880
  # a[0, 2] = 'foo' # => "foo"
888
881
  # a # => ["foo", 2]
889
882
  #
890
883
  # If `start` is negative, counts backwards from the end of the array:
884
+ #
891
885
  # a = [:foo, 'bar', 2]
892
886
  # a[-2, 2] = 'foo' # => "foo"
893
887
  # a # => [:foo, "foo"]
@@ -895,17 +889,20 @@ class Array[unchecked out Elem] < Object
895
889
  # If `start` is non-negative and outside the array (` >= self.size`), extends
896
890
  # the array with `nil`, assigns `object` at offset `start`, and ignores
897
891
  # `length`:
892
+ #
898
893
  # a = [:foo, 'bar', 2]
899
894
  # a[6, 50] = 'foo' # => "foo"
900
895
  # a # => [:foo, "bar", 2, nil, nil, nil, "foo"]
901
896
  #
902
897
  # If `length` is zero, shifts elements at and following offset `start` and
903
898
  # assigns `object` at offset `start`:
899
+ #
904
900
  # a = [:foo, 'bar', 2]
905
901
  # a[1, 0] = 'foo' # => "foo"
906
902
  # a # => [:foo, "foo", "bar", 2]
907
903
  #
908
904
  # If `length` is too large for the existing array, does not extend the array:
905
+ #
909
906
  # a = [:foo, 'bar', 2]
910
907
  # a[1, 5] = 'foo' # => "foo"
911
908
  # a # => [:foo, "foo"]
@@ -913,29 +910,34 @@ class Array[unchecked out Elem] < Object
913
910
  # When Range argument `range` is given and `object` is an Array, removes `length
914
911
  # - 1` elements beginning at offset `start`, and assigns `object` at offset
915
912
  # `start`:
913
+ #
916
914
  # a = [:foo, 'bar', 2]
917
915
  # a[0..1] = 'foo' # => "foo"
918
916
  # a # => ["foo", 2]
919
917
  #
920
918
  # if `range.begin` is negative, counts backwards from the end of the array:
919
+ #
921
920
  # a = [:foo, 'bar', 2]
922
921
  # a[-2..2] = 'foo' # => "foo"
923
922
  # a # => [:foo, "foo"]
924
923
  #
925
924
  # If the array length is less than `range.begin`, assigns `object` at offset
926
925
  # `range.begin`, and ignores `length`:
926
+ #
927
927
  # a = [:foo, 'bar', 2]
928
928
  # a[6..50] = 'foo' # => "foo"
929
929
  # a # => [:foo, "bar", 2, nil, nil, nil, "foo"]
930
930
  #
931
931
  # If `range.end` is zero, shifts elements at and following offset `start` and
932
932
  # assigns `object` at offset `start`:
933
+ #
933
934
  # a = [:foo, 'bar', 2]
934
935
  # a[1..0] = 'foo' # => "foo"
935
936
  # a # => [:foo, "foo", "bar", 2]
936
937
  #
937
938
  # If `range.end` is negative, assigns `object` at offset `start`, retains
938
939
  # `range.end.abs -1` elements past that, and removes those beyond:
940
+ #
939
941
  # a = [:foo, 'bar', 2]
940
942
  # a[1..-1] = 'foo' # => "foo"
941
943
  # a # => [:foo, "foo"]
@@ -949,6 +951,7 @@ class Array[unchecked out Elem] < Object
949
951
  #
950
952
  # If `range.end` is too large for the existing array, replaces array elements,
951
953
  # but does not extend the array with `nil` values:
954
+ #
952
955
  # a = [:foo, 'bar', 2]
953
956
  # a[1..5] = 'foo' # => "foo"
954
957
  # a # => [:foo, "foo"]
@@ -971,6 +974,7 @@ class Array[unchecked out Elem] < Object
971
974
  #
972
975
  # With no block given and no argument, returns `true` if `self` contains only
973
976
  # truthy elements, `false` otherwise:
977
+ #
974
978
  # [0, 1, :foo].all? # => true
975
979
  # [0, nil, 2].all? # => false
976
980
  # [].all? # => true
@@ -978,11 +982,13 @@ class Array[unchecked out Elem] < Object
978
982
  # With a block given and no argument, calls the block with each element in
979
983
  # `self`; returns `true` if the block returns only truthy values, `false`
980
984
  # otherwise:
985
+ #
981
986
  # [0, 1, 2].all? { |element| element < 3 } # => true
982
987
  # [0, 1, 2].all? { |element| element < 2 } # => false
983
988
  #
984
989
  # If argument `obj` is given, returns `true` if `obj.===` every element, `false`
985
990
  # otherwise:
991
+ #
986
992
  # ['food', 'fool', 'foot'].all?(/foo/) # => true
987
993
  # ['food', 'drink'].all?(/bar/) # => false
988
994
  # [].all?(/foo/) # => true
@@ -1005,6 +1011,7 @@ class Array[unchecked out Elem] < Object
1005
1011
  #
1006
1012
  # With no block given and no argument, returns `true` if `self` has any truthy
1007
1013
  # element, `false` otherwise:
1014
+ #
1008
1015
  # [nil, 0, false].any? # => true
1009
1016
  # [nil, false].any? # => false
1010
1017
  # [].any? # => false
@@ -1012,11 +1019,13 @@ class Array[unchecked out Elem] < Object
1012
1019
  # With a block given and no argument, calls the block with each element in
1013
1020
  # `self`; returns `true` if the block returns any truthy value, `false`
1014
1021
  # otherwise:
1022
+ #
1015
1023
  # [0, 1, 2].any? {|element| element > 1 } # => true
1016
1024
  # [0, 1, 2].any? {|element| element > 2 } # => false
1017
1025
  #
1018
1026
  # If argument `obj` is given, returns `true` if `obj`.`===` any element, `false`
1019
1027
  # otherwise:
1028
+ #
1020
1029
  # ['food', 'drink'].any?(/foo/) # => true
1021
1030
  # ['food', 'drink'].any?(/bar/) # => false
1022
1031
  # [].any?(/foo/) # => false
@@ -1031,10 +1040,12 @@ class Array[unchecked out Elem] < Object
1031
1040
  # Appends trailing elements.
1032
1041
  #
1033
1042
  # Appends each argument in `objects` to `self`; returns `self`:
1043
+ #
1034
1044
  # a = [:foo, 'bar', 2]
1035
1045
  # a.push(:baz, :bat) # => [:foo, "bar", 2, :baz, :bat]
1036
1046
  #
1037
1047
  # Appends each argument as one element, even if it is another Array:
1048
+ #
1038
1049
  # a = [:foo, 'bar', 2]
1039
1050
  # a1 = a.push([:baz, :bat], [:bam, :bad])
1040
1051
  # a1 # => [:foo, "bar", 2, [:baz, :bat], [:bam, :bad]]
@@ -1051,6 +1062,7 @@ class Array[unchecked out Elem] < Object
1051
1062
  # -->
1052
1063
  # Returns the first element in `self` that is an Array whose first element `==`
1053
1064
  # `obj`:
1065
+ #
1054
1066
  # a = [{foo: 0}, [2, 4], [4, 5, 6], [4, 5]]
1055
1067
  # a.assoc(4) # => [4, 5, 6]
1056
1068
  #
@@ -1100,6 +1112,7 @@ class Array[unchecked out Elem] < Object
1100
1112
  # - array.clear -> self
1101
1113
  # -->
1102
1114
  # Removes all elements from `self`:
1115
+ #
1103
1116
  # a = [:foo, 'bar', 2]
1104
1117
  # a.clear # => []
1105
1118
  #
@@ -1112,6 +1125,7 @@ class Array[unchecked out Elem] < Object
1112
1125
  # -->
1113
1126
  # Calls the block, if given, with each element of `self`; returns a new Array
1114
1127
  # whose elements are the return values from the block:
1128
+ #
1115
1129
  # a = [:foo, 'bar', 2]
1116
1130
  # a1 = a.map {|element| element.class }
1117
1131
  # a1 # => [Symbol, String, Integer]
@@ -1133,10 +1147,12 @@ class Array[unchecked out Elem] < Object
1133
1147
  # -->
1134
1148
  # Calls the block, if given, with each element; replaces the element with the
1135
1149
  # block's return value:
1150
+ #
1136
1151
  # a = [:foo, 'bar', 2]
1137
1152
  # a.map! { |element| element.class } # => [Symbol, String, Integer]
1138
1153
  #
1139
1154
  # Returns a new Enumerator if no block given:
1155
+ #
1140
1156
  # a = [:foo, 'bar', 2]
1141
1157
  # a1 = a.map!
1142
1158
  # a1 # => #<Enumerator: [:foo, "bar", 2]:map!>
@@ -1159,35 +1175,43 @@ class Array[unchecked out Elem] < Object
1159
1175
  # `self`.
1160
1176
  #
1161
1177
  # Example:
1178
+ #
1162
1179
  # a = [0, 1, 2]
1163
1180
  # a.combination(2) {|combination| p combination }
1164
1181
  #
1165
1182
  # Output:
1183
+ #
1166
1184
  # [0, 1]
1167
1185
  # [0, 2]
1168
1186
  # [1, 2]
1169
1187
  #
1170
1188
  # Another example:
1189
+ #
1171
1190
  # a = [0, 1, 2]
1172
1191
  # a.combination(3) {|combination| p combination }
1173
1192
  #
1174
1193
  # Output:
1194
+ #
1175
1195
  # [0, 1, 2]
1176
1196
  #
1177
1197
  # When `n` is zero, calls the block once with a new empty Array:
1198
+ #
1178
1199
  # a = [0, 1, 2]
1179
1200
  # a1 = a.combination(0) {|combination| p combination }
1180
1201
  #
1181
1202
  # Output:
1203
+ #
1182
1204
  # []
1183
1205
  #
1184
1206
  # When `n` is out of range (negative or larger than `self.size`), does not call
1185
1207
  # the block:
1208
+ #
1186
1209
  # a = [0, 1, 2]
1187
1210
  # a.combination(-1) {|combination| fail 'Cannot happen' }
1188
1211
  # a.combination(4) {|combination| fail 'Cannot happen' }
1189
1212
  #
1190
1213
  # Returns a new Enumerator if no block given:
1214
+ #
1191
1215
  # a = [0, 1, 2]
1192
1216
  # a.combination(2) # => #<Enumerator: [0, 1, 2]:combination(2)>
1193
1217
  #
@@ -1199,6 +1223,7 @@ class Array[unchecked out Elem] < Object
1199
1223
  # - array.compact -> new_array
1200
1224
  # -->
1201
1225
  # Returns a new Array containing all non-`nil` elements from `self`:
1226
+ #
1202
1227
  # a = [nil, 0, nil, 1, nil, 2, nil]
1203
1228
  # a.compact # => [0, 1, 2]
1204
1229
  #
@@ -1220,6 +1245,7 @@ class Array[unchecked out Elem] < Object
1220
1245
  # -->
1221
1246
  # Adds to `array` all elements from each Array in `other_arrays`; returns
1222
1247
  # `self`:
1248
+ #
1223
1249
  # a = [0, 1]
1224
1250
  # a.concat([2, 3], [4, 5]) # => [0, 1, 2, 3, 4, 5]
1225
1251
  #
@@ -1234,19 +1260,22 @@ class Array[unchecked out Elem] < Object
1234
1260
  # Returns a count of specified elements.
1235
1261
  #
1236
1262
  # With no argument and no block, returns the count of all elements:
1263
+ #
1237
1264
  # [0, 1, 2].count # => 3
1238
1265
  # [].count # => 0
1239
1266
  #
1240
1267
  # With argument `obj`, returns the count of elements `==` to `obj`:
1268
+ #
1241
1269
  # [0, 1, 2, 0.0].count(0) # => 2
1242
1270
  # [0, 1, 2].count(3) # => 0
1243
1271
  #
1244
1272
  # With no argument and a block given, calls the block with each element; returns
1245
1273
  # the count of elements for which the block returns a truthy value:
1274
+ #
1246
1275
  # [0, 1, 2, 3].count {|element| element > 1} # => 2
1247
1276
  #
1248
1277
  # With argument `obj` and a block given, issues a warning, ignores the block,
1249
- # and returns the count of elements `==` to `obj`:
1278
+ # and returns the count of elements `==` to `obj`.
1250
1279
  #
1251
1280
  def count: () -> ::Integer
1252
1281
  | (Elem obj) -> ::Integer
@@ -1262,15 +1291,18 @@ class Array[unchecked out Elem] < Object
1262
1291
  # When called with positive Integer argument `count` and a block, calls the
1263
1292
  # block with each element, then does so again, until it has done so `count`
1264
1293
  # times; returns `nil`:
1294
+ #
1265
1295
  # output = []
1266
1296
  # [0, 1].cycle(2) {|element| output.push(element) } # => nil
1267
1297
  # output # => [0, 1, 0, 1]
1268
1298
  #
1269
1299
  # If `count` is zero or negative, does not call the block:
1300
+ #
1270
1301
  # [0, 1].cycle(0) {|element| fail 'Cannot happen' } # => nil
1271
1302
  # [0, 1].cycle(-1) {|element| fail 'Cannot happen' } # => nil
1272
1303
  #
1273
1304
  # When a block is given, and argument is omitted or `nil`, cycles forever:
1305
+ #
1274
1306
  # # Prints 0 and 1 forever.
1275
1307
  # [0, 1].cycle {|element| puts element }
1276
1308
  # [0, 1].cycle(nil) {|element| puts element }
@@ -1296,10 +1328,11 @@ class Array[unchecked out Elem] < Object
1296
1328
  # - array.delete(obj) -> deleted_object
1297
1329
  # - array.delete(obj) {|nosuch| ... } -> deleted_object or block_return
1298
1330
  # -->
1299
- # Removes zero or more elements from `self`; returns `self`.
1331
+ # Removes zero or more elements from `self`.
1300
1332
  #
1301
1333
  # When no block is given, removes from `self` each element `ele` such that `ele
1302
1334
  # == obj`; returns the last deleted element:
1335
+ #
1303
1336
  # s1 = 'bar'; s2 = 'bar'
1304
1337
  # a = [:foo, s1, 2, s2]
1305
1338
  # a.delete('bar') # => "bar"
@@ -1312,12 +1345,14 @@ class Array[unchecked out Elem] < Object
1312
1345
  #
1313
1346
  # If any such elements are found, ignores the block and returns the last deleted
1314
1347
  # element:
1348
+ #
1315
1349
  # s1 = 'bar'; s2 = 'bar'
1316
1350
  # a = [:foo, s1, 2, s2]
1317
1351
  # deleted_obj = a.delete('bar') {|obj| fail 'Cannot happen' }
1318
1352
  # a # => [:foo, 2]
1319
1353
  #
1320
1354
  # If no such elements are found, returns the block's return value:
1355
+ #
1321
1356
  # a = [:foo, 'bar', 2]
1322
1357
  # a.delete(:nosuch) {|obj| "#{obj} not found" } # => "nosuch not found"
1323
1358
  #
@@ -1331,6 +1366,7 @@ class Array[unchecked out Elem] < Object
1331
1366
  # Deletes an element from `self`, per the given Integer `index`.
1332
1367
  #
1333
1368
  # When `index` is non-negative, deletes the element at offset `index`:
1369
+ #
1334
1370
  # a = [:foo, 'bar', 2]
1335
1371
  # a.delete_at(1) # => "bar"
1336
1372
  # a # => [:foo, 2]
@@ -1338,6 +1374,7 @@ class Array[unchecked out Elem] < Object
1338
1374
  # If index is too large, returns `nil`.
1339
1375
  #
1340
1376
  # When `index` is negative, counts backward from the end of the array:
1377
+ #
1341
1378
  # a = [:foo, 'bar', 2]
1342
1379
  # a.delete_at(-2) # => "bar"
1343
1380
  # a # => [:foo, 2]
@@ -1351,14 +1388,18 @@ class Array[unchecked out Elem] < Object
1351
1388
  # - array.delete_if {|element| ... } -> self
1352
1389
  # - array.delete_if -> Enumerator
1353
1390
  # -->
1354
- # Removes each element in `self` for which the block returns a truthy value;
1355
- # returns `self`:
1356
- # a = [:foo, 'bar', 2, 'bat']
1357
- # a.delete_if {|element| element.to_s.start_with?('b') } # => [:foo, 2]
1391
+ # Removes each element in +self+ for which the block returns a truthy value;
1392
+ # returns +self+:
1358
1393
  #
1359
- # Returns a new Enumerator if no block given:
1360
- # a = [:foo, 'bar', 2]
1361
- # a.delete_if # => #<Enumerator: [:foo, "bar", 2]:delete_if>
1394
+ # a = [:foo, 'bar', 2, 'bat']
1395
+ # a.delete_if {|element| element.to_s.start_with?('b') } # => [:foo, 2]
1396
+ #
1397
+ # Returns a new \Enumerator if no block given:
1398
+ #
1399
+ # a = [:foo, 'bar', 2]
1400
+ # a.delete_if # => #<Enumerator: [:foo, "bar", 2]:delete_if>
1401
+ #
1402
+ # 3
1362
1403
  #
1363
1404
  def delete_if: () { (Elem item) -> boolish } -> self
1364
1405
  | () -> ::Enumerator[Elem, self]
@@ -1370,6 +1411,7 @@ class Array[unchecked out Elem] < Object
1370
1411
  # Returns a new Array containing only those elements from `self` that are not
1371
1412
  # found in any of the Arrays `other_arrays`; items are compared using `eql?`;
1372
1413
  # order from `self` is preserved:
1414
+ #
1373
1415
  # [0, 1, 1, 2, 1, 1, 3, 1, 1].difference([1]) # => [0, 2, 3]
1374
1416
  # [0, 1, 2, 3].difference([3, 0], [1, 3]) # => [2]
1375
1417
  # [0, 1, 2].difference([4]) # => [0, 1, 2]
@@ -1389,6 +1431,7 @@ class Array[unchecked out Elem] < Object
1389
1431
  # [Dig Methods](rdoc-ref:dig_methods.rdoc).
1390
1432
  #
1391
1433
  # Examples:
1434
+ #
1392
1435
  # a = [:foo, [:bar, :baz, [:bat, :bam]]]
1393
1436
  # a.dig(1) # => [:bar, :baz, [:bat, :bam]]
1394
1437
  # a.dig(1, 2) # => [:bat, :bam]
@@ -1406,6 +1449,7 @@ class Array[unchecked out Elem] < Object
1406
1449
  # `n` is a non-negative Integer; does not modify `self`.
1407
1450
  #
1408
1451
  # Examples:
1452
+ #
1409
1453
  # a = [0, 1, 2, 3, 4, 5]
1410
1454
  # a.drop(0) # => [0, 1, 2, 3, 4, 5]
1411
1455
  # a.drop(1) # => [1, 2, 3, 4, 5]
@@ -1424,10 +1468,12 @@ class Array[unchecked out Elem] < Object
1424
1468
  # With a block given, calls the block with each successive element of `self`;
1425
1469
  # stops if the block returns `false` or `nil`; returns a new Array *omitting*
1426
1470
  # those elements for which the block returned a truthy value:
1471
+ #
1427
1472
  # a = [0, 1, 2, 3, 4, 5]
1428
1473
  # a.drop_while {|element| element < 3 } # => [3, 4, 5]
1429
1474
  #
1430
1475
  # With no block given, returns a new Enumerator:
1476
+ #
1431
1477
  # [0, 1].drop_while # => # => #<Enumerator: [0, 1]:drop_while>
1432
1478
  #
1433
1479
  def drop_while: () { (Elem obj) -> boolish } -> ::Array[Elem]
@@ -1442,29 +1488,35 @@ class Array[unchecked out Elem] < Object
1442
1488
  #
1443
1489
  # When a block given, passes each successive array element to the block; returns
1444
1490
  # `self`:
1491
+ #
1445
1492
  # a = [:foo, 'bar', 2]
1446
1493
  # a.each {|element| puts "#{element.class} #{element}" }
1447
1494
  #
1448
1495
  # Output:
1496
+ #
1449
1497
  # Symbol foo
1450
1498
  # String bar
1451
1499
  # Integer 2
1452
1500
  #
1453
1501
  # Allows the array to be modified during iteration:
1502
+ #
1454
1503
  # a = [:foo, 'bar', 2]
1455
1504
  # a.each {|element| puts element; a.clear if element.to_s.start_with?('b') }
1456
1505
  #
1457
1506
  # Output:
1507
+ #
1458
1508
  # foo
1459
1509
  # bar
1460
1510
  #
1461
1511
  # When no block given, returns a new Enumerator:
1462
1512
  # a = [:foo, 'bar', 2]
1513
+ #
1463
1514
  # e = a.each
1464
1515
  # e # => #<Enumerator: [:foo, "bar", 2]:each>
1465
1516
  # a1 = e.each {|element| puts "#{element.class} #{element}" }
1466
1517
  #
1467
1518
  # Output:
1519
+ #
1468
1520
  # Symbol foo
1469
1521
  # String bar
1470
1522
  # Integer 2
@@ -1483,29 +1535,35 @@ class Array[unchecked out Elem] < Object
1483
1535
  #
1484
1536
  # When a block given, passes each successive array index to the block; returns
1485
1537
  # `self`:
1538
+ #
1486
1539
  # a = [:foo, 'bar', 2]
1487
1540
  # a.each_index {|index| puts "#{index} #{a[index]}" }
1488
1541
  #
1489
1542
  # Output:
1543
+ #
1490
1544
  # 0 foo
1491
1545
  # 1 bar
1492
1546
  # 2 2
1493
1547
  #
1494
1548
  # Allows the array to be modified during iteration:
1549
+ #
1495
1550
  # a = [:foo, 'bar', 2]
1496
1551
  # a.each_index {|index| puts index; a.clear if index > 0 }
1497
1552
  #
1498
1553
  # Output:
1554
+ #
1499
1555
  # 0
1500
1556
  # 1
1501
1557
  #
1502
1558
  # When no block given, returns a new Enumerator:
1559
+ #
1503
1560
  # a = [:foo, 'bar', 2]
1504
1561
  # e = a.each_index
1505
1562
  # e # => #<Enumerator: [:foo, "bar", 2]:each_index>
1506
1563
  # a1 = e.each {|index| puts "#{index} #{a[index]}"}
1507
1564
  #
1508
1565
  # Output:
1566
+ #
1509
1567
  # 0 foo
1510
1568
  # 1 bar
1511
1569
  # 2 2
@@ -1529,14 +1587,15 @@ class Array[unchecked out Elem] < Object
1529
1587
  # -->
1530
1588
  # Returns `true` if `self` and `other_array` are the same size, and if, for each
1531
1589
  # index `i` in `self`, `self[i].eql? other_array[i]`:
1590
+ #
1532
1591
  # a0 = [:foo, 'bar', 2]
1533
1592
  # a1 = [:foo, 'bar', 2]
1534
1593
  # a1.eql?(a0) # => true
1535
1594
  #
1536
1595
  # Otherwise, returns `false`.
1537
1596
  #
1538
- # This method is different from method [Array#==](#method-i-3D-3D), which
1539
- # compares using method `Object#==`.
1597
+ # This method is different from method Array#==, which compares using method
1598
+ # `Object#==`.
1540
1599
  #
1541
1600
  def eql?: (untyped other) -> bool
1542
1601
 
@@ -1550,16 +1609,19 @@ class Array[unchecked out Elem] < Object
1550
1609
  #
1551
1610
  # With the single Integer argument `index`, returns the element at offset
1552
1611
  # `index`:
1612
+ #
1553
1613
  # a = [:foo, 'bar', 2]
1554
1614
  # a.fetch(1) # => "bar"
1555
1615
  #
1556
1616
  # If `index` is negative, counts from the end of the array:
1617
+ #
1557
1618
  # a = [:foo, 'bar', 2]
1558
1619
  # a.fetch(-1) # => 2
1559
1620
  # a.fetch(-2) # => "bar"
1560
1621
  #
1561
1622
  # With arguments `index` and `default_value`, returns the element at offset
1562
1623
  # `index` if index is in range, otherwise returns `default_value`:
1624
+ #
1563
1625
  # a = [:foo, 'bar', 2]
1564
1626
  # a.fetch(1, nil) # => "bar"
1565
1627
  #
@@ -1590,6 +1652,7 @@ class Array[unchecked out Elem] < Object
1590
1652
  #
1591
1653
  # With argument `obj` and no block given, replaces all elements with that one
1592
1654
  # object:
1655
+ #
1593
1656
  # a = ['a', 'b', 'c', 'd']
1594
1657
  # a # => ["a", "b", "c", "d"]
1595
1658
  # a.fill(:X) # => [:X, :X, :X, :X]
@@ -1599,10 +1662,12 @@ class Array[unchecked out Elem] < Object
1599
1662
  #
1600
1663
  # If `start` is in range (`0 <= start < array.size`), replaces all elements from
1601
1664
  # offset `start` through the end:
1665
+ #
1602
1666
  # a = ['a', 'b', 'c', 'd']
1603
1667
  # a.fill(:X, 2) # => ["a", "b", :X, :X]
1604
1668
  #
1605
1669
  # If `start` is too large (`start >= array.size`), does nothing:
1670
+ #
1606
1671
  # a = ['a', 'b', 'c', 'd']
1607
1672
  # a.fill(:X, 4) # => ["a", "b", "c", "d"]
1608
1673
  # a = ['a', 'b', 'c', 'd']
@@ -1610,10 +1675,12 @@ class Array[unchecked out Elem] < Object
1610
1675
  #
1611
1676
  # If `start` is negative, counts from the end (starting index is `start +
1612
1677
  # array.size`):
1678
+ #
1613
1679
  # a = ['a', 'b', 'c', 'd']
1614
1680
  # a.fill(:X, -2) # => ["a", "b", :X, :X]
1615
1681
  #
1616
1682
  # If `start` is too small (less than and far from zero), replaces all elements:
1683
+ #
1617
1684
  # a = ['a', 'b', 'c', 'd']
1618
1685
  # a.fill(:X, -6) # => [:X, :X, :X, :X]
1619
1686
  # a = ['a', 'b', 'c', 'd']
@@ -1624,20 +1691,24 @@ class Array[unchecked out Elem] < Object
1624
1691
  #
1625
1692
  # If `start` is in range, replaces `length` elements beginning at offset
1626
1693
  # `start`:
1694
+ #
1627
1695
  # a = ['a', 'b', 'c', 'd']
1628
1696
  # a.fill(:X, 1, 1) # => ["a", :X, "c", "d"]
1629
1697
  #
1630
1698
  # If `start` is negative, counts from the end:
1699
+ #
1631
1700
  # a = ['a', 'b', 'c', 'd']
1632
1701
  # a.fill(:X, -2, 1) # => ["a", "b", :X, "d"]
1633
1702
  #
1634
1703
  # If `start` is large (`start >= array.size`), extends `self` with `nil`:
1704
+ #
1635
1705
  # a = ['a', 'b', 'c', 'd']
1636
1706
  # a.fill(:X, 5, 0) # => ["a", "b", "c", "d", nil]
1637
1707
  # a = ['a', 'b', 'c', 'd']
1638
1708
  # a.fill(:X, 5, 2) # => ["a", "b", "c", "d", nil, :X, :X]
1639
1709
  #
1640
1710
  # If `length` is zero or negative, replaces no elements:
1711
+ #
1641
1712
  # a = ['a', 'b', 'c', 'd']
1642
1713
  # a.fill(:X, 1, 0) # => ["a", "b", "c", "d"]
1643
1714
  # a.fill(:X, 1, -1) # => ["a", "b", "c", "d"]
@@ -1647,14 +1718,17 @@ class Array[unchecked out Elem] < Object
1647
1718
  #
1648
1719
  # If the range is positive and ascending (`0 < range.begin <= range.end`),
1649
1720
  # replaces elements from `range.begin` to `range.end`:
1721
+ #
1650
1722
  # a = ['a', 'b', 'c', 'd']
1651
1723
  # a.fill(:X, (1..1)) # => ["a", :X, "c", "d"]
1652
1724
  #
1653
1725
  # If `range.first` is negative, replaces no elements:
1726
+ #
1654
1727
  # a = ['a', 'b', 'c', 'd']
1655
1728
  # a.fill(:X, (-1..1)) # => ["a", "b", "c", "d"]
1656
1729
  #
1657
1730
  # If `range.last` is negative, counts from the end:
1731
+ #
1658
1732
  # a = ['a', 'b', 'c', 'd']
1659
1733
  # a.fill(:X, (0..-2)) # => [:X, :X, :X, "d"]
1660
1734
  # a = ['a', 'b', 'c', 'd']
@@ -1662,6 +1736,7 @@ class Array[unchecked out Elem] < Object
1662
1736
  #
1663
1737
  # If `range.last` and `range.last` are both negative, both count from the end of
1664
1738
  # the array:
1739
+ #
1665
1740
  # a = ['a', 'b', 'c', 'd']
1666
1741
  # a.fill(:X, (-1..-1)) # => ["a", "b", "c", :X]
1667
1742
  # a = ['a', 'b', 'c', 'd']
@@ -1669,29 +1744,34 @@ class Array[unchecked out Elem] < Object
1669
1744
  #
1670
1745
  # With no arguments and a block given, calls the block with each index; replaces
1671
1746
  # the corresponding element with the block's return value:
1747
+ #
1672
1748
  # a = ['a', 'b', 'c', 'd']
1673
1749
  # a.fill { |index| "new_#{index}" } # => ["new_0", "new_1", "new_2", "new_3"]
1674
1750
  #
1675
1751
  # With argument `start` and a block given, calls the block with each index from
1676
1752
  # offset `start` to the end; replaces the corresponding element with the block's
1677
- # return value:
1753
+ # return value.
1678
1754
  #
1679
1755
  # If start is in range (`0 <= start < array.size`), replaces from offset `start`
1680
1756
  # to the end:
1757
+ #
1681
1758
  # a = ['a', 'b', 'c', 'd']
1682
1759
  # a.fill(1) { |index| "new_#{index}" } # => ["a", "new_1", "new_2", "new_3"]
1683
1760
  #
1684
1761
  # If `start` is too large(`start >= array.size`), does nothing:
1762
+ #
1685
1763
  # a = ['a', 'b', 'c', 'd']
1686
1764
  # a.fill(4) { |index| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
1687
1765
  # a = ['a', 'b', 'c', 'd']
1688
1766
  # a.fill(4) { |index| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
1689
1767
  #
1690
1768
  # If `start` is negative, counts from the end:
1769
+ #
1691
1770
  # a = ['a', 'b', 'c', 'd']
1692
1771
  # a.fill(-2) { |index| "new_#{index}" } # => ["a", "b", "new_2", "new_3"]
1693
1772
  #
1694
1773
  # If start is too small (`start <= -array.size`, replaces all elements:
1774
+ #
1695
1775
  # a = ['a', 'b', 'c', 'd']
1696
1776
  # a.fill(-6) { |index| "new_#{index}" } # => ["new_0", "new_1", "new_2", "new_3"]
1697
1777
  # a = ['a', 'b', 'c', 'd']
@@ -1703,20 +1783,24 @@ class Array[unchecked out Elem] < Object
1703
1783
  #
1704
1784
  # If `start` is in range, replaces `length` elements beginning at offset
1705
1785
  # `start`:
1786
+ #
1706
1787
  # a = ['a', 'b', 'c', 'd']
1707
1788
  # a.fill(1, 1) { |index| "new_#{index}" } # => ["a", "new_1", "c", "d"]
1708
1789
  #
1709
1790
  # If start is negative, counts from the end:
1791
+ #
1710
1792
  # a = ['a', 'b', 'c', 'd']
1711
1793
  # a.fill(-2, 1) { |index| "new_#{index}" } # => ["a", "b", "new_2", "d"]
1712
1794
  #
1713
1795
  # If `start` is large (`start >= array.size`), extends `self` with `nil`:
1796
+ #
1714
1797
  # a = ['a', 'b', 'c', 'd']
1715
1798
  # a.fill(5, 0) { |index| "new_#{index}" } # => ["a", "b", "c", "d", nil]
1716
1799
  # a = ['a', 'b', 'c', 'd']
1717
1800
  # a.fill(5, 2) { |index| "new_#{index}" } # => ["a", "b", "c", "d", nil, "new_5", "new_6"]
1718
1801
  #
1719
1802
  # If `length` is zero or less, replaces no elements:
1803
+ #
1720
1804
  # a = ['a', 'b', 'c', 'd']
1721
1805
  # a.fill(1, 0) { |index| "new_#{index}" } # => ["a", "b", "c", "d"]
1722
1806
  # a.fill(1, -1) { |index| "new_#{index}" } # => ["a", "b", "c", "d"]
@@ -1727,20 +1811,24 @@ class Array[unchecked out Elem] < Object
1727
1811
  #
1728
1812
  # If the range is positive and ascending (`range 0 < range.begin <= range.end`,
1729
1813
  # replaces elements from `range.begin` to `range.end`:
1814
+ #
1730
1815
  # a = ['a', 'b', 'c', 'd']
1731
1816
  # a.fill(1..1) { |index| "new_#{index}" } # => ["a", "new_1", "c", "d"]
1732
1817
  #
1733
1818
  # If `range.first` is negative, does nothing:
1819
+ #
1734
1820
  # a = ['a', 'b', 'c', 'd']
1735
1821
  # a.fill(-1..1) { |index| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
1736
1822
  #
1737
1823
  # If `range.last` is negative, counts from the end:
1824
+ #
1738
1825
  # a = ['a', 'b', 'c', 'd']
1739
1826
  # a.fill(0..-2) { |index| "new_#{index}" } # => ["new_0", "new_1", "new_2", "d"]
1740
1827
  # a = ['a', 'b', 'c', 'd']
1741
1828
  # a.fill(1..-2) { |index| "new_#{index}" } # => ["a", "new_1", "new_2", "d"]
1742
1829
  #
1743
1830
  # If `range.first` and `range.last` are both negative, both count from the end:
1831
+ #
1744
1832
  # a = ['a', 'b', 'c', 'd']
1745
1833
  # a.fill(-1..-1) { |index| "new_#{index}" } # => ["a", "b", "c", "new_3"]
1746
1834
  # a = ['a', 'b', 'c', 'd']
@@ -1756,11 +1844,13 @@ class Array[unchecked out Elem] < Object
1756
1844
  # Calls the block, if given, with each element of `self`; returns a new Array
1757
1845
  # containing those elements of `self` for which the block returns a truthy
1758
1846
  # value:
1847
+ #
1759
1848
  # a = [:foo, 'bar', 2, :bam]
1760
1849
  # a1 = a.select {|element| element.to_s.start_with?('b') }
1761
1850
  # a1 # => ["bar", :bam]
1762
1851
  #
1763
1852
  # Returns a new Enumerator if no block given:
1853
+ #
1764
1854
  # a = [:foo, 'bar', 2, :bam]
1765
1855
  # a.select # => #<Enumerator: [:foo, "bar", 2, :bam]:select>
1766
1856
  #
@@ -1774,12 +1864,14 @@ class Array[unchecked out Elem] < Object
1774
1864
  # those elements for which the block returns `false` or `nil`.
1775
1865
  #
1776
1866
  # Returns `self` if any elements were removed:
1867
+ #
1777
1868
  # a = [:foo, 'bar', 2, :bam]
1778
1869
  # a.select! {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
1779
1870
  #
1780
1871
  # Returns `nil` if no elements were removed.
1781
1872
  #
1782
1873
  # Returns a new Enumerator if no block given:
1874
+ #
1783
1875
  # a = [:foo, 'bar', 2, :bam]
1784
1876
  # a.select! # => #<Enumerator: [:foo, "bar", 2, :bam]:select!>
1785
1877
  #
@@ -1798,6 +1890,7 @@ class Array[unchecked out Elem] < Object
1798
1890
  #
1799
1891
  # When argument `object` is given but no block, returns the index of the first
1800
1892
  # element `element` for which `object == element`:
1893
+ #
1801
1894
  # a = [:foo, 'bar', 2, 'bar']
1802
1895
  # a.index('bar') # => 1
1803
1896
  #
@@ -1806,12 +1899,14 @@ class Array[unchecked out Elem] < Object
1806
1899
  # When both argument `object` and a block are given, calls the block with each
1807
1900
  # successive element; returns the index of the first element for which the block
1808
1901
  # returns a truthy value:
1902
+ #
1809
1903
  # a = [:foo, 'bar', 2, 'bar']
1810
1904
  # a.index {|element| element == 'bar' } # => 1
1811
1905
  #
1812
1906
  # Returns `nil` if the block never returns a truthy value.
1813
1907
  #
1814
1908
  # When neither an argument nor a block is given, returns a new Enumerator:
1909
+ #
1815
1910
  # a = [:foo, 'bar', 2]
1816
1911
  # e = a.index
1817
1912
  # e # => #<Enumerator: [:foo, "bar", 2]:index>
@@ -1833,6 +1928,7 @@ class Array[unchecked out Elem] < Object
1833
1928
  # Returns elements from `self`; does not modify `self`.
1834
1929
  #
1835
1930
  # When no argument is given, returns the first element:
1931
+ #
1836
1932
  # a = [:foo, 'bar', 2]
1837
1933
  # a.first # => :foo
1838
1934
  # a # => [:foo, "bar", 2]
@@ -1841,14 +1937,17 @@ class Array[unchecked out Elem] < Object
1841
1937
  #
1842
1938
  # When non-negative Integer argument `n` is given, returns the first `n`
1843
1939
  # elements in a new Array:
1940
+ #
1844
1941
  # a = [:foo, 'bar', 2]
1845
1942
  # a.first(2) # => [:foo, "bar"]
1846
1943
  #
1847
1944
  # If `n >= array.size`, returns all elements:
1945
+ #
1848
1946
  # a = [:foo, 'bar', 2]
1849
1947
  # a.first(50) # => [:foo, "bar", 2]
1850
1948
  #
1851
1949
  # If `n == 0` returns an new empty Array:
1950
+ #
1852
1951
  # a = [:foo, 'bar', 2]
1853
1952
  # a.first(0) # []
1854
1953
  #
@@ -1869,6 +1968,7 @@ class Array[unchecked out Elem] < Object
1869
1968
  #
1870
1969
  # With non-negative Integer argument `level`, flattens recursively through
1871
1970
  # `level` levels:
1971
+ #
1872
1972
  # a = [ 0, [ 1, [2, 3], 4 ], 5 ]
1873
1973
  # a.flatten(0) # => [0, [1, [2, 3], 4], 5]
1874
1974
  # a = [ 0, [ 1, [2, 3], 4 ], 5 ]
@@ -1880,6 +1980,7 @@ class Array[unchecked out Elem] < Object
1880
1980
  #
1881
1981
  # With no argument, a `nil` argument, or with negative argument `level`,
1882
1982
  # flattens all levels:
1983
+ #
1883
1984
  # a = [ 0, [ 1, [2, 3], 4 ], 5 ]
1884
1985
  # a.flatten # => [0, 1, 2, 3, 4, 5]
1885
1986
  # [0, 1, 2].flatten # => [0, 1, 2]
@@ -1901,6 +2002,7 @@ class Array[unchecked out Elem] < Object
1901
2002
  #
1902
2003
  # With non-negative Integer argument `level`, flattens recursively through
1903
2004
  # `level` levels:
2005
+ #
1904
2006
  # a = [ 0, [ 1, [2, 3], 4 ], 5 ]
1905
2007
  # a.flatten!(1) # => [0, 1, [2, 3], 4, 5]
1906
2008
  # a = [ 0, [ 1, [2, 3], 4 ], 5 ]
@@ -1911,6 +2013,7 @@ class Array[unchecked out Elem] < Object
1911
2013
  #
1912
2014
  # With no argument, a `nil` argument, or with negative argument `level`,
1913
2015
  # flattens all levels:
2016
+ #
1914
2017
  # a = [ 0, [ 1, [2, 3], 4 ], 5 ]
1915
2018
  # a.flatten! # => [0, 1, 2, 3, 4, 5]
1916
2019
  # [0, 1, 2].flatten! # => nil
@@ -1930,6 +2033,7 @@ class Array[unchecked out Elem] < Object
1930
2033
  #
1931
2034
  # Two arrays with the same content will have the same hash code (and will
1932
2035
  # compare using eql?):
2036
+ #
1933
2037
  # [0, 1, 2].hash == [0, 1, 2].hash # => true
1934
2038
  # [0, 1, 2].hash == [0, 1, 3].hash # => false
1935
2039
  #
@@ -1941,6 +2045,7 @@ class Array[unchecked out Elem] < Object
1941
2045
  # -->
1942
2046
  # Returns `true` if for some index `i` in `self`, `obj == self[i]`; otherwise
1943
2047
  # `false`:
2048
+ #
1944
2049
  # [0, 1, 2].include?(2) # => true
1945
2050
  # [0, 1, 2].include?(3) # => false
1946
2051
  #
@@ -1951,6 +2056,7 @@ class Array[unchecked out Elem] < Object
1951
2056
  #
1952
2057
  # When argument `object` is given but no block, returns the index of the first
1953
2058
  # element `element` for which `object == element`:
2059
+ #
1954
2060
  # a = [:foo, 'bar', 2, 'bar']
1955
2061
  # a.index('bar') # => 1
1956
2062
  #
@@ -1959,12 +2065,14 @@ class Array[unchecked out Elem] < Object
1959
2065
  # When both argument `object` and a block are given, calls the block with each
1960
2066
  # successive element; returns the index of the first element for which the block
1961
2067
  # returns a truthy value:
2068
+ #
1962
2069
  # a = [:foo, 'bar', 2, 'bar']
1963
2070
  # a.index {|element| element == 'bar' } # => 1
1964
2071
  #
1965
2072
  # Returns `nil` if the block never returns a truthy value.
1966
2073
  #
1967
2074
  # When neither an argument nor a block is given, returns a new Enumerator:
2075
+ #
1968
2076
  # a = [:foo, 'bar', 2]
1969
2077
  # e = a.index
1970
2078
  # e # => #<Enumerator: [:foo, "bar", 2]:index>
@@ -1985,15 +2093,18 @@ class Array[unchecked out Elem] < Object
1985
2093
  #
1986
2094
  # When `index` is non-negative, inserts all given `objects` before the element
1987
2095
  # at offset `index`:
2096
+ #
1988
2097
  # a = [:foo, 'bar', 2]
1989
2098
  # a.insert(1, :bat, :bam) # => [:foo, :bat, :bam, "bar", 2]
1990
2099
  #
1991
2100
  # Extends the array if `index` is beyond the array (`index >= self.size`):
2101
+ #
1992
2102
  # a = [:foo, 'bar', 2]
1993
2103
  # a.insert(5, :bat, :bam)
1994
2104
  # a # => [:foo, "bar", 2, nil, nil, :bat, :bam]
1995
2105
  #
1996
2106
  # Does nothing if no objects given:
2107
+ #
1997
2108
  # a = [:foo, 'bar', 2]
1998
2109
  # a.insert(1)
1999
2110
  # a.insert(50)
@@ -2002,6 +2113,7 @@ class Array[unchecked out Elem] < Object
2002
2113
  #
2003
2114
  # When `index` is negative, inserts all given `objects` *after* the element at
2004
2115
  # offset `index+self.size`:
2116
+ #
2005
2117
  # a = [:foo, 'bar', 2]
2006
2118
  # a.insert(-2, :bat, :bam)
2007
2119
  # a # => [:foo, "bar", :bat, :bam, 2]
@@ -2014,6 +2126,7 @@ class Array[unchecked out Elem] < Object
2014
2126
  # -->
2015
2127
  # Returns the new String formed by calling method `#inspect` on each array
2016
2128
  # element:
2129
+ #
2017
2130
  # a = [:foo, 'bar', 2]
2018
2131
  # a.inspect # => "[:foo, \"bar\", 2]"
2019
2132
  #
@@ -2026,7 +2139,7 @@ class Array[unchecked out Elem] < Object
2026
2139
  # - ary.intersect?(other_ary) -> true or false
2027
2140
  # -->
2028
2141
  # Returns `true` if the array and `other_ary` have at least one element in
2029
- # common, otherwise returns `false`.
2142
+ # common, otherwise returns `false`:
2030
2143
  #
2031
2144
  # a = [ 1, 2, 3 ]
2032
2145
  # b = [ 3, 4, 5 ]
@@ -2043,10 +2156,12 @@ class Array[unchecked out Elem] < Object
2043
2156
  # Returns a new Array containing each element found both in `self` and in all of
2044
2157
  # the given Arrays `other_arrays`; duplicates are omitted; items are compared
2045
2158
  # using `eql?`:
2159
+ #
2046
2160
  # [0, 1, 2, 3].intersection([0, 1, 2], [0, 1, 3]) # => [0, 1]
2047
2161
  # [0, 0, 1, 1, 2, 3].intersection([0, 1, 2], [0, 1, 3]) # => [0, 1]
2048
2162
  #
2049
2163
  # Preserves order from `self`:
2164
+ #
2050
2165
  # [0, 1, 2].intersection([2, 1, 0]) # => [0, 1, 2]
2051
2166
  #
2052
2167
  # Returns a copy of `self` if no arguments given.
@@ -2061,22 +2176,26 @@ class Array[unchecked out Elem] < Object
2061
2176
  # - array.join(separator = $,) -> new_string
2062
2177
  # -->
2063
2178
  # Returns the new String formed by joining the array elements after conversion.
2064
- # For each element `element`
2179
+ # For each element `element`:
2180
+ #
2065
2181
  # * Uses `element.to_s` if `element` is not a `kind_of?(Array)`.
2066
2182
  # * Uses recursive `element.join(separator)` if `element` is a
2067
2183
  # `kind_of?(Array)`.
2068
2184
  #
2069
2185
  #
2070
2186
  # With no argument, joins using the output field separator, `$,`:
2187
+ #
2071
2188
  # a = [:foo, 'bar', 2]
2072
2189
  # $, # => nil
2073
2190
  # a.join # => "foobar2"
2074
2191
  #
2075
2192
  # With string argument `separator`, joins using that separator:
2193
+ #
2076
2194
  # a = [:foo, 'bar', 2]
2077
2195
  # a.join("\n") # => "foo\nbar\n2"
2078
2196
  #
2079
2197
  # Joins recursively for nested Arrays:
2198
+ #
2080
2199
  # a = [:foo, [:bar, [:baz, :bat]]]
2081
2200
  # a.join # => "foobarbazbat"
2082
2201
  #
@@ -2089,10 +2208,12 @@ class Array[unchecked out Elem] < Object
2089
2208
  # -->
2090
2209
  # Retains those elements for which the block returns a truthy value; deletes all
2091
2210
  # other elements; returns `self`:
2211
+ #
2092
2212
  # a = [:foo, 'bar', 2, :bam]
2093
2213
  # a.keep_if {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
2094
2214
  #
2095
2215
  # Returns a new Enumerator if no block given:
2216
+ #
2096
2217
  # a = [:foo, 'bar', 2, :bam]
2097
2218
  # a.keep_if # => #<Enumerator: [:foo, "bar", 2, :bam]:keep_if>
2098
2219
  #
@@ -2107,22 +2228,26 @@ class Array[unchecked out Elem] < Object
2107
2228
  # Returns elements from `self`; `self` is not modified.
2108
2229
  #
2109
2230
  # When no argument is given, returns the last element:
2231
+ #
2110
2232
  # a = [:foo, 'bar', 2]
2111
2233
  # a.last # => 2
2112
2234
  # a # => [:foo, "bar", 2]
2113
2235
  #
2114
2236
  # If `self` is empty, returns `nil`.
2115
2237
  #
2116
- # When non-negative Innteger argument `n` is given, returns the last `n`
2117
- # elements in a new Array:
2238
+ # When non-negative Integer argument `n` is given, returns the last `n` elements
2239
+ # in a new Array:
2240
+ #
2118
2241
  # a = [:foo, 'bar', 2]
2119
2242
  # a.last(2) # => ["bar", 2]
2120
2243
  #
2121
2244
  # If `n >= array.size`, returns all elements:
2245
+ #
2122
2246
  # a = [:foo, 'bar', 2]
2123
2247
  # a.last(50) # => [:foo, "bar", 2]
2124
2248
  #
2125
2249
  # If `n == 0`, returns an new empty Array:
2250
+ #
2126
2251
  # a = [:foo, 'bar', 2]
2127
2252
  # a.last(0) # []
2128
2253
  #
@@ -2142,6 +2267,7 @@ class Array[unchecked out Elem] < Object
2142
2267
  # <!-- rdoc-file=array.c -->
2143
2268
  # Calls the block, if given, with each element of `self`; returns a new Array
2144
2269
  # whose elements are the return values from the block:
2270
+ #
2145
2271
  # a = [:foo, 'bar', 2]
2146
2272
  # a1 = a.map {|element| element.class }
2147
2273
  # a1 # => [Symbol, String, Integer]
@@ -2158,10 +2284,12 @@ class Array[unchecked out Elem] < Object
2158
2284
  # <!-- rdoc-file=array.c -->
2159
2285
  # Calls the block, if given, with each element; replaces the element with the
2160
2286
  # block's return value:
2287
+ #
2161
2288
  # a = [:foo, 'bar', 2]
2162
2289
  # a.map! { |element| element.class } # => [Symbol, String, Integer]
2163
2290
  #
2164
2291
  # Returns a new Enumerator if no block given:
2292
+ #
2165
2293
  # a = [:foo, 'bar', 2]
2166
2294
  # a1 = a.map!
2167
2295
  # a1 # => #<Enumerator: [:foo, "bar", 2]:map!>
@@ -2178,6 +2306,7 @@ class Array[unchecked out Elem] < Object
2178
2306
  # - array.max(n) {|a, b| ... } -> new_array
2179
2307
  # -->
2180
2308
  # Returns one of the following:
2309
+ #
2181
2310
  # * The maximum-valued element from `self`.
2182
2311
  # * A new Array of maximum-valued elements selected from `self`.
2183
2312
  #
@@ -2187,10 +2316,12 @@ class Array[unchecked out Elem] < Object
2187
2316
  #
2188
2317
  # With no argument and no block, returns the element in `self` having the
2189
2318
  # maximum value per method `<=>`:
2319
+ #
2190
2320
  # [0, 1, 2].max # => 2
2191
2321
  #
2192
2322
  # With an argument Integer `n` and no block, returns a new Array with at most
2193
2323
  # `n` elements, in descending order per method `<=>`:
2324
+ #
2194
2325
  # [0, 1, 2, 3].max(3) # => [3, 2, 1]
2195
2326
  # [0, 1, 2, 3].max(6) # => [3, 2, 1, 0]
2196
2327
  #
@@ -2198,10 +2329,12 @@ class Array[unchecked out Elem] < Object
2198
2329
  #
2199
2330
  # With a block and no argument, calls the block `self.size-1` times to compare
2200
2331
  # elements; returns the element having the maximum value per the block:
2332
+ #
2201
2333
  # ['0', '00', '000'].max {|a, b| a.size <=> b.size } # => "000"
2202
2334
  #
2203
2335
  # With an argument `n` and a block, returns a new Array with at most `n`
2204
2336
  # elements, in descending order per the block:
2337
+ #
2205
2338
  # ['0', '00', '000'].max(2) {|a, b| a.size <=> b.size } # => ["000", "00"]
2206
2339
  #
2207
2340
  def max: () -> Elem?
@@ -2217,6 +2350,7 @@ class Array[unchecked out Elem] < Object
2217
2350
  # - array.min(n) { |a, b| ... } -> new_array
2218
2351
  # -->
2219
2352
  # Returns one of the following:
2353
+ #
2220
2354
  # * The minimum-valued element from `self`.
2221
2355
  # * A new Array of minimum-valued elements selected from `self`.
2222
2356
  #
@@ -2226,10 +2360,12 @@ class Array[unchecked out Elem] < Object
2226
2360
  #
2227
2361
  # With no argument and no block, returns the element in `self` having the
2228
2362
  # minimum value per method `<=>`:
2363
+ #
2229
2364
  # [0, 1, 2].min # => 0
2230
2365
  #
2231
2366
  # With Integer argument `n` and no block, returns a new Array with at most `n`
2232
2367
  # elements, in ascending order per method `<=>`:
2368
+ #
2233
2369
  # [0, 1, 2, 3].min(3) # => [0, 1, 2]
2234
2370
  # [0, 1, 2, 3].min(6) # => [0, 1, 2, 3]
2235
2371
  #
@@ -2237,10 +2373,12 @@ class Array[unchecked out Elem] < Object
2237
2373
  #
2238
2374
  # With a block and no argument, calls the block `self.size-1` times to compare
2239
2375
  # elements; returns the element having the minimum value per the block:
2376
+ #
2240
2377
  # ['0', '00', '000'].min { |a, b| a.size <=> b.size } # => "0"
2241
2378
  #
2242
2379
  # With an argument `n` and a block, returns a new Array with at most `n`
2243
2380
  # elements, in ascending order per the block:
2381
+ #
2244
2382
  # ['0', '00', '000'].min(2) {|a, b| a.size <=> b.size } # => ["0", "00"]
2245
2383
  #
2246
2384
  alias min max
@@ -2256,11 +2394,13 @@ class Array[unchecked out Elem] < Object
2256
2394
  # When no block is given, each element in `self` must respond to method `<=>`
2257
2395
  # with an Integer; returns a new 2-element Array containing the minimum and
2258
2396
  # maximum values from `self`, per method `<=>`:
2397
+ #
2259
2398
  # [0, 1, 2].minmax # => [0, 2]
2260
2399
  #
2261
2400
  # When a block is given, the block must return an Integer; the block is called
2262
2401
  # `self.size-1` times to compare elements; returns a new 2-element Array
2263
2402
  # containing the minimum and maximum values from `self`, per the block:
2403
+ #
2264
2404
  # ['0', '00', '000'].minmax {|a, b| a.size <=> b.size } # => ["0", "000"]
2265
2405
  #
2266
2406
  def minmax: () -> [ Elem?, Elem? ]
@@ -2276,6 +2416,7 @@ class Array[unchecked out Elem] < Object
2276
2416
  #
2277
2417
  # With no block given and no argument, returns `true` if `self` has no truthy
2278
2418
  # elements, `false` otherwise:
2419
+ #
2279
2420
  # [nil, false].none? # => true
2280
2421
  # [nil, 0, false].none? # => false
2281
2422
  # [].none? # => true
@@ -2283,11 +2424,13 @@ class Array[unchecked out Elem] < Object
2283
2424
  # With a block given and no argument, calls the block with each element in
2284
2425
  # `self`; returns `true` if the block returns no truthy value, `false`
2285
2426
  # otherwise:
2427
+ #
2286
2428
  # [0, 1, 2].none? {|element| element > 3 } # => true
2287
2429
  # [0, 1, 2].none? {|element| element > 1 } # => false
2288
2430
  #
2289
2431
  # If argument `obj` is given, returns `true` if `obj.===` no element, `false`
2290
2432
  # otherwise:
2433
+ #
2291
2434
  # ['food', 'drink'].none?(/bar/) # => true
2292
2435
  # ['food', 'drink'].none?(/foo/) # => false
2293
2436
  # [].none?(/foo/) # => true
@@ -2308,6 +2451,7 @@ class Array[unchecked out Elem] < Object
2308
2451
  #
2309
2452
  # With no block given and no argument, returns `true` if `self` has exactly one
2310
2453
  # truthy element, `false` otherwise:
2454
+ #
2311
2455
  # [nil, 0].one? # => true
2312
2456
  # [0, 0].one? # => false
2313
2457
  # [nil, nil].one? # => false
@@ -2316,12 +2460,14 @@ class Array[unchecked out Elem] < Object
2316
2460
  # With a block given and no argument, calls the block with each element in
2317
2461
  # `self`; returns `true` if the block a truthy value for exactly one element,
2318
2462
  # `false` otherwise:
2463
+ #
2319
2464
  # [0, 1, 2].one? {|element| element > 0 } # => false
2320
2465
  # [0, 1, 2].one? {|element| element > 1 } # => true
2321
2466
  # [0, 1, 2].one? {|element| element > 2 } # => false
2322
2467
  #
2323
2468
  # If argument `obj` is given, returns `true` if `obj.===` exactly one element,
2324
2469
  # `false` otherwise:
2470
+ #
2325
2471
  # [0, 1, 2].one?(0) # => true
2326
2472
  # [0, 0, 1].one?(0) # => false
2327
2473
  # [1, 1, 2].one?(0) # => false
@@ -2335,140 +2481,10 @@ class Array[unchecked out Elem] < Object
2335
2481
 
2336
2482
  # <!--
2337
2483
  # rdoc-file=pack.rb
2338
- # - arr.pack( aTemplateString ) -> aBinaryString
2339
- # - arr.pack( aTemplateString, buffer: aBufferString ) -> aBufferString
2340
- # -->
2341
- # Packs the contents of *arr* into a binary sequence according to the directives
2342
- # in *aTemplateString* (see the table below) Directives ``A,'' ``a,'' and ``Z''
2343
- # may be followed by a count, which gives the width of the resulting field. The
2344
- # remaining directives also may take a count, indicating the number of array
2345
- # elements to convert. If the count is an asterisk (```*`''), all remaining
2346
- # array elements will be converted. Any of the directives ```sSiIlL`'' may be
2347
- # followed by an underscore (```_`'') or exclamation mark (```!`'') to use the
2348
- # underlying platform's native size for the specified type; otherwise, they use
2349
- # a platform-independent size. Spaces are ignored in the template string. See
2350
- # also String#unpack.
2351
- #
2352
- # a = [ "a", "b", "c" ]
2353
- # n = [ 65, 66, 67 ]
2354
- # a.pack("A3A3A3") #=> "a b c "
2355
- # a.pack("a3a3a3") #=> "a\000\000b\000\000c\000\000"
2356
- # n.pack("ccc") #=> "ABC"
2357
- #
2358
- # If *aBufferString* is specified and its capacity is enough, `pack` uses it as
2359
- # the buffer and returns it. When the offset is specified by the beginning of
2360
- # *aTemplateString*, the result is filled after the offset. If original contents
2361
- # of *aBufferString* exists and it's longer than the offset, the rest of
2362
- # *offsetOfBuffer* are overwritten by the result. If it's shorter, the gap is
2363
- # filled with ```\0`''.
2364
- #
2365
- # # packed data is appended by default
2366
- # [255].pack("C", buffer:"foo".b) #=> "foo\xFF"
2367
- #
2368
- # # "@0" (offset 0) specifies that packed data is filled from beginning.
2369
- # # Also, original data after packed data is removed. ("oo" is removed.)
2370
- # [255].pack("@0C", buffer:"foo".b) #=> "\xFF"
2371
- #
2372
- # # If the offset is bigger than the original length, \x00 is filled.
2373
- # [255].pack("@5C", buffer:"foo".b) #=> "foo\x00\x00\xFF"
2374
- #
2375
- # Note that ``buffer:'' option does not guarantee not to allocate memory in
2376
- # `pack`. If the capacity of *aBufferString* is not enough, `pack` allocates
2377
- # memory.
2378
- #
2379
- # Directives for `pack`.
2380
- #
2381
- # Integer | Array |
2382
- # Directive | Element | Meaning
2383
- # ----------------------------------------------------------------------------
2384
- # C | Integer | 8-bit unsigned (unsigned char)
2385
- # S | Integer | 16-bit unsigned, native endian (uint16_t)
2386
- # L | Integer | 32-bit unsigned, native endian (uint32_t)
2387
- # Q | Integer | 64-bit unsigned, native endian (uint64_t)
2388
- # J | Integer | pointer width unsigned, native endian (uintptr_t)
2389
- # | | (J is available since Ruby 2.3.)
2390
- # | |
2391
- # c | Integer | 8-bit signed (signed char)
2392
- # s | Integer | 16-bit signed, native endian (int16_t)
2393
- # l | Integer | 32-bit signed, native endian (int32_t)
2394
- # q | Integer | 64-bit signed, native endian (int64_t)
2395
- # j | Integer | pointer width signed, native endian (intptr_t)
2396
- # | | (j is available since Ruby 2.3.)
2397
- # | |
2398
- # S_ S! | Integer | unsigned short, native endian
2399
- # I I_ I! | Integer | unsigned int, native endian
2400
- # L_ L! | Integer | unsigned long, native endian
2401
- # Q_ Q! | Integer | unsigned long long, native endian (ArgumentError
2402
- # | | if the platform has no long long type.)
2403
- # | | (Q_ and Q! is available since Ruby 2.1.)
2404
- # J! | Integer | uintptr_t, native endian (same with J)
2405
- # | | (J! is available since Ruby 2.3.)
2406
- # | |
2407
- # s_ s! | Integer | signed short, native endian
2408
- # i i_ i! | Integer | signed int, native endian
2409
- # l_ l! | Integer | signed long, native endian
2410
- # q_ q! | Integer | signed long long, native endian (ArgumentError
2411
- # | | if the platform has no long long type.)
2412
- # | | (q_ and q! is available since Ruby 2.1.)
2413
- # j! | Integer | intptr_t, native endian (same with j)
2414
- # | | (j! is available since Ruby 2.3.)
2415
- # | |
2416
- # S> s> S!> s!> | Integer | same as the directives without ">" except
2417
- # L> l> L!> l!> | | big endian
2418
- # I!> i!> | | (available since Ruby 1.9.3)
2419
- # Q> q> Q!> q!> | | "S>" is the same as "n"
2420
- # J> j> J!> j!> | | "L>" is the same as "N"
2421
- # | |
2422
- # S< s< S!< s!< | Integer | same as the directives without "<" except
2423
- # L< l< L!< l!< | | little endian
2424
- # I!< i!< | | (available since Ruby 1.9.3)
2425
- # Q< q< Q!< q!< | | "S<" is the same as "v"
2426
- # J< j< J!< j!< | | "L<" is the same as "V"
2427
- # | |
2428
- # n | Integer | 16-bit unsigned, network (big-endian) byte order
2429
- # N | Integer | 32-bit unsigned, network (big-endian) byte order
2430
- # v | Integer | 16-bit unsigned, VAX (little-endian) byte order
2431
- # V | Integer | 32-bit unsigned, VAX (little-endian) byte order
2432
- # | |
2433
- # U | Integer | UTF-8 character
2434
- # w | Integer | BER-compressed integer
2435
- #
2436
- # Float | Array |
2437
- # Directive | Element | Meaning
2438
- # ---------------------------------------------------------------------------
2439
- # D d | Float | double-precision, native format
2440
- # F f | Float | single-precision, native format
2441
- # E | Float | double-precision, little-endian byte order
2442
- # e | Float | single-precision, little-endian byte order
2443
- # G | Float | double-precision, network (big-endian) byte order
2444
- # g | Float | single-precision, network (big-endian) byte order
2445
- #
2446
- # String | Array |
2447
- # Directive | Element | Meaning
2448
- # ---------------------------------------------------------------------------
2449
- # A | String | arbitrary binary string (space padded, count is width)
2450
- # a | String | arbitrary binary string (null padded, count is width)
2451
- # Z | String | same as ``a'', except that null is added with *
2452
- # B | String | bit string (MSB first)
2453
- # b | String | bit string (LSB first)
2454
- # H | String | hex string (high nibble first)
2455
- # h | String | hex string (low nibble first)
2456
- # u | String | UU-encoded string
2457
- # M | String | quoted printable, MIME encoding (see also RFC2045)
2458
- # | | (text mode but input must use LF and output LF)
2459
- # m | String | base64 encoded string (see RFC 2045)
2460
- # | | (if count is 0, no line feed are added, see RFC 4648)
2461
- # | | (count specifies input bytes between each LF,
2462
- # | | rounded down to nearest multiple of 3)
2463
- # P | String | pointer to a structure (fixed-length string)
2464
- # p | String | pointer to a null-terminated string
2465
- #
2466
- # Misc. | Array |
2467
- # Directive | Element | Meaning
2468
- # ---------------------------------------------------------------------------
2469
- # @ | --- | moves to absolute position
2470
- # X | --- | back up a byte
2471
- # x | --- | null byte
2484
+ # - pack(template, buffer: nil) -> string
2485
+ # -->
2486
+ # Formats each element in `self` into a binary string; returns that string. See
2487
+ # [Packed Data](rdoc-ref:packed_data.rdoc).
2472
2488
  #
2473
2489
  def pack: (string fmt, ?buffer: String?) -> String
2474
2490
 
@@ -2487,10 +2503,12 @@ class Array[unchecked out Elem] < Object
2487
2503
  # `self`.
2488
2504
  #
2489
2505
  # Example:
2506
+ #
2490
2507
  # a = [0, 1, 2]
2491
2508
  # a.permutation(2) {|permutation| p permutation }
2492
2509
  #
2493
2510
  # Output:
2511
+ #
2494
2512
  # [0, 1]
2495
2513
  # [0, 2]
2496
2514
  # [1, 0]
@@ -2499,10 +2517,12 @@ class Array[unchecked out Elem] < Object
2499
2517
  # [2, 1]
2500
2518
  #
2501
2519
  # Another example:
2520
+ #
2502
2521
  # a = [0, 1, 2]
2503
2522
  # a.permutation(3) {|permutation| p permutation }
2504
2523
  #
2505
2524
  # Output:
2525
+ #
2506
2526
  # [0, 1, 2]
2507
2527
  # [0, 2, 1]
2508
2528
  # [1, 0, 2]
@@ -2511,24 +2531,29 @@ class Array[unchecked out Elem] < Object
2511
2531
  # [2, 1, 0]
2512
2532
  #
2513
2533
  # When `n` is zero, calls the block once with a new empty Array:
2534
+ #
2514
2535
  # a = [0, 1, 2]
2515
2536
  # a.permutation(0) {|permutation| p permutation }
2516
2537
  #
2517
2538
  # Output:
2539
+ #
2518
2540
  # []
2519
2541
  #
2520
2542
  # When `n` is out of range (negative or larger than `self.size`), does not call
2521
2543
  # the block:
2544
+ #
2522
2545
  # a = [0, 1, 2]
2523
2546
  # a.permutation(-1) {|permutation| fail 'Cannot happen' }
2524
2547
  # a.permutation(4) {|permutation| fail 'Cannot happen' }
2525
2548
  #
2526
2549
  # When a block given but no argument, behaves the same as
2527
2550
  # `a.permutation(a.size)`:
2551
+ #
2528
2552
  # a = [0, 1, 2]
2529
2553
  # a.permutation {|permutation| p permutation }
2530
2554
  #
2531
2555
  # Output:
2556
+ #
2532
2557
  # [0, 1, 2]
2533
2558
  # [0, 2, 1]
2534
2559
  # [1, 0, 2]
@@ -2537,6 +2562,7 @@ class Array[unchecked out Elem] < Object
2537
2562
  # [2, 1, 0]
2538
2563
  #
2539
2564
  # Returns a new Enumerator if no block given:
2565
+ #
2540
2566
  # a = [0, 1, 2]
2541
2567
  # a.permutation # => #<Enumerator: [0, 1, 2]:permutation>
2542
2568
  # a.permutation(2) # => #<Enumerator: [0, 1, 2]:permutation(2)>
@@ -2553,18 +2579,21 @@ class Array[unchecked out Elem] < Object
2553
2579
  #
2554
2580
  # When no argument is given and `self` is not empty, removes and returns the
2555
2581
  # last element:
2582
+ #
2556
2583
  # a = [:foo, 'bar', 2]
2557
2584
  # a.pop # => 2
2558
2585
  # a # => [:foo, "bar"]
2559
2586
  #
2560
2587
  # Returns `nil` if the array is empty.
2561
2588
  #
2562
- # When a non-negative Integer argument `n` is given and is in range, removes and
2563
- # returns the last `n` elements in a new Array:
2589
+ # When a non-negative Integer argument `n` is given and is in range,
2590
+ #
2591
+ # removes and returns the last `n` elements in a new Array:
2564
2592
  # a = [:foo, 'bar', 2]
2565
2593
  # a.pop(2) # => ["bar", 2]
2566
2594
  #
2567
2595
  # If `n` is positive and out of range, removes and returns all elements:
2596
+ #
2568
2597
  # a = [:foo, 'bar', 2]
2569
2598
  # a.pop(50) # => [:foo, "bar", 2]
2570
2599
  #
@@ -2575,6 +2604,7 @@ class Array[unchecked out Elem] < Object
2575
2604
 
2576
2605
  # <!-- rdoc-file=array.c -->
2577
2606
  # Prepends the given `objects` to `self`:
2607
+ #
2578
2608
  # a = [:foo, 'bar', 2]
2579
2609
  # a.unshift(:bam, :bat) # => [:bam, :bat, :foo, "bar", 2]
2580
2610
  #
@@ -2590,13 +2620,15 @@ class Array[unchecked out Elem] < Object
2590
2620
  # - array.product(*other_arrays) {|combination| ... } -> self
2591
2621
  # -->
2592
2622
  # Computes and returns or yields all combinations of elements from all the
2593
- # Arrays, including both `self` and `other_arrays`.
2623
+ # Arrays, including both `self` and `other_arrays`:
2624
+ #
2594
2625
  # * The number of combinations is the product of the sizes of all the arrays,
2595
2626
  # including both `self` and `other_arrays`.
2596
2627
  # * The order of the returned combinations is indeterminate.
2597
2628
  #
2598
2629
  #
2599
2630
  # When no block is given, returns the combinations as an Array of Arrays:
2631
+ #
2600
2632
  # a = [0, 1, 2]
2601
2633
  # a1 = [3, 4]
2602
2634
  # a2 = [5, 6]
@@ -2611,12 +2643,15 @@ class Array[unchecked out Elem] < Object
2611
2643
  #
2612
2644
  # If no argument is given, returns an Array of 1-element Arrays, each containing
2613
2645
  # an element of `self`:
2646
+ #
2614
2647
  # a.product # => [[0], [1], [2]]
2615
2648
  #
2616
2649
  # When a block is given, yields each combination as an Array; returns `self`:
2650
+ #
2617
2651
  # a.product(a1) {|combination| p combination }
2618
2652
  #
2619
2653
  # Output:
2654
+ #
2620
2655
  # [0, 3]
2621
2656
  # [0, 4]
2622
2657
  # [1, 3]
@@ -2625,12 +2660,15 @@ class Array[unchecked out Elem] < Object
2625
2660
  # [2, 4]
2626
2661
  #
2627
2662
  # If any argument is an empty Array, does not call the block:
2663
+ #
2628
2664
  # a.product(a1, a2, []) {|combination| fail 'Cannot happen' }
2629
2665
  #
2630
2666
  # If no argument is given, yields each element of `self` as a 1-element Array:
2667
+ #
2631
2668
  # a.product {|combination| p combination }
2632
2669
  #
2633
2670
  # Output:
2671
+ #
2634
2672
  # [0]
2635
2673
  # [1]
2636
2674
  # [2]
@@ -2647,10 +2685,12 @@ class Array[unchecked out Elem] < Object
2647
2685
  # Appends trailing elements.
2648
2686
  #
2649
2687
  # Appends each argument in `objects` to `self`; returns `self`:
2688
+ #
2650
2689
  # a = [:foo, 'bar', 2]
2651
2690
  # a.push(:baz, :bat) # => [:foo, "bar", 2, :baz, :bat]
2652
2691
  #
2653
2692
  # Appends each argument as one element, even if it is another Array:
2693
+ #
2654
2694
  # a = [:foo, 'bar', 2]
2655
2695
  # a1 = a.push([:baz, :bat], [:bam, :bad])
2656
2696
  # a1 # => [:foo, "bar", 2, [:baz, :bat], [:bam, :bad]]
@@ -2667,6 +2707,7 @@ class Array[unchecked out Elem] < Object
2667
2707
  # -->
2668
2708
  # Returns the first element in `self` that is an Array whose second element `==`
2669
2709
  # `obj`:
2710
+ #
2670
2711
  # a = [{foo: 0}, [2, 4], [4, 5, 6], [4, 5]]
2671
2712
  # a.rassoc(4) # => [2, 4]
2672
2713
  #
@@ -2683,11 +2724,13 @@ class Array[unchecked out Elem] < Object
2683
2724
  # -->
2684
2725
  # Returns a new Array whose elements are all those from `self` for which the
2685
2726
  # block returns `false` or `nil`:
2727
+ #
2686
2728
  # a = [:foo, 'bar', 2, 'bat']
2687
2729
  # a1 = a.reject {|element| element.to_s.start_with?('b') }
2688
2730
  # a1 # => [:foo, 2]
2689
2731
  #
2690
2732
  # Returns a new Enumerator if no block given:
2733
+ #
2691
2734
  # a = [:foo, 'bar', 2]
2692
2735
  # a.reject # => #<Enumerator: [:foo, "bar", 2]:reject>
2693
2736
  #
@@ -2701,12 +2744,14 @@ class Array[unchecked out Elem] < Object
2701
2744
  # Removes each element for which the block returns a truthy value.
2702
2745
  #
2703
2746
  # Returns `self` if any elements removed:
2747
+ #
2704
2748
  # a = [:foo, 'bar', 2, 'bat']
2705
2749
  # a.reject! {|element| element.to_s.start_with?('b') } # => [:foo, 2]
2706
2750
  #
2707
2751
  # Returns `nil` if no elements removed.
2708
2752
  #
2709
2753
  # Returns a new Enumerator if no block given:
2754
+ #
2710
2755
  # a = [:foo, 'bar', 2]
2711
2756
  # a.reject! # => #<Enumerator: [:foo, "bar", 2]:reject!>
2712
2757
  #
@@ -2727,18 +2772,22 @@ class Array[unchecked out Elem] < Object
2727
2772
  # of combinations is `(n+1)(n+2)/2`.
2728
2773
  #
2729
2774
  # `n` = 1:
2775
+ #
2730
2776
  # a = [0, 1, 2]
2731
2777
  # a.repeated_combination(1) {|combination| p combination }
2732
2778
  #
2733
2779
  # Output:
2780
+ #
2734
2781
  # [0]
2735
2782
  # [1]
2736
2783
  # [2]
2737
2784
  #
2738
2785
  # `n` = 2:
2786
+ #
2739
2787
  # a.repeated_combination(2) {|combination| p combination }
2740
2788
  #
2741
2789
  # Output:
2790
+ #
2742
2791
  # [0, 0]
2743
2792
  # [0, 1]
2744
2793
  # [0, 2]
@@ -2749,14 +2798,17 @@ class Array[unchecked out Elem] < Object
2749
2798
  # If `n` is zero, calls the block once with an empty Array.
2750
2799
  #
2751
2800
  # If `n` is negative, does not call the block:
2801
+ #
2752
2802
  # a.repeated_combination(-1) {|combination| fail 'Cannot happen' }
2753
2803
  #
2754
2804
  # Returns a new Enumerator if no block given:
2805
+ #
2755
2806
  # a = [0, 1, 2]
2756
2807
  # a.repeated_combination(2) # => #<Enumerator: [0, 1, 2]:combination(2)>
2757
2808
  #
2758
2809
  # Using Enumerators, it's convenient to show the combinations and counts for
2759
2810
  # some values of `n`:
2811
+ #
2760
2812
  # e = a.repeated_combination(0)
2761
2813
  # e.size # => 1
2762
2814
  # e.to_a # => [[]]
@@ -2784,18 +2836,22 @@ class Array[unchecked out Elem] < Object
2784
2836
  # of permutations is `self.size**n`.
2785
2837
  #
2786
2838
  # `n` = 1:
2839
+ #
2787
2840
  # a = [0, 1, 2]
2788
2841
  # a.repeated_permutation(1) {|permutation| p permutation }
2789
2842
  #
2790
2843
  # Output:
2844
+ #
2791
2845
  # [0]
2792
2846
  # [1]
2793
2847
  # [2]
2794
2848
  #
2795
2849
  # `n` = 2:
2850
+ #
2796
2851
  # a.repeated_permutation(2) {|permutation| p permutation }
2797
2852
  #
2798
2853
  # Output:
2854
+ #
2799
2855
  # [0, 0]
2800
2856
  # [0, 1]
2801
2857
  # [0, 2]
@@ -2809,14 +2865,17 @@ class Array[unchecked out Elem] < Object
2809
2865
  # If `n` is zero, calls the block once with an empty Array.
2810
2866
  #
2811
2867
  # If `n` is negative, does not call the block:
2868
+ #
2812
2869
  # a.repeated_permutation(-1) {|permutation| fail 'Cannot happen' }
2813
2870
  #
2814
2871
  # Returns a new Enumerator if no block given:
2872
+ #
2815
2873
  # a = [0, 1, 2]
2816
2874
  # a.repeated_permutation(2) # => #<Enumerator: [0, 1, 2]:permutation(2)>
2817
2875
  #
2818
2876
  # Using Enumerators, it's convenient to show the permutations and counts for
2819
2877
  # some values of `n`:
2878
+ #
2820
2879
  # e = a.repeated_permutation(0)
2821
2880
  # e.size # => 1
2822
2881
  # e.to_a # => [[]]
@@ -2833,6 +2892,7 @@ class Array[unchecked out Elem] < Object
2833
2892
  # <!-- rdoc-file=array.c -->
2834
2893
  # Replaces the content of `self` with the content of `other_array`; returns
2835
2894
  # `self`:
2895
+ #
2836
2896
  # a = [:foo, 'bar', 2]
2837
2897
  # a.replace(['foo', :bar, 3]) # => ["foo", :bar, 3]
2838
2898
  #
@@ -2842,7 +2902,8 @@ class Array[unchecked out Elem] < Object
2842
2902
  # rdoc-file=array.c
2843
2903
  # - array.reverse -> new_array
2844
2904
  # -->
2845
- # Returns a new Array with the elements of `self` in reverse order.
2905
+ # Returns a new Array with the elements of `self` in reverse order:
2906
+ #
2846
2907
  # a = ['foo', 'bar', 'two']
2847
2908
  # a1 = a.reverse
2848
2909
  # a1 # => ["two", "bar", "foo"]
@@ -2854,6 +2915,7 @@ class Array[unchecked out Elem] < Object
2854
2915
  # - array.reverse! -> self
2855
2916
  # -->
2856
2917
  # Reverses `self` in place:
2918
+ #
2857
2919
  # a = ['foo', 'bar', 'two']
2858
2920
  # a.reverse! # => ["two", "bar", "foo"]
2859
2921
  #
@@ -2868,29 +2930,35 @@ class Array[unchecked out Elem] < Object
2868
2930
  #
2869
2931
  # When a block given, passes, in reverse order, each element to the block;
2870
2932
  # returns `self`:
2933
+ #
2871
2934
  # a = [:foo, 'bar', 2]
2872
2935
  # a.reverse_each {|element| puts "#{element.class} #{element}" }
2873
2936
  #
2874
2937
  # Output:
2938
+ #
2875
2939
  # Integer 2
2876
2940
  # String bar
2877
2941
  # Symbol foo
2878
2942
  #
2879
2943
  # Allows the array to be modified during iteration:
2944
+ #
2880
2945
  # a = [:foo, 'bar', 2]
2881
2946
  # a.reverse_each {|element| puts element; a.clear if element.to_s.start_with?('b') }
2882
2947
  #
2883
2948
  # Output:
2949
+ #
2884
2950
  # 2
2885
2951
  # bar
2886
2952
  #
2887
2953
  # When no block given, returns a new Enumerator:
2954
+ #
2888
2955
  # a = [:foo, 'bar', 2]
2889
2956
  # e = a.reverse_each
2890
2957
  # e # => #<Enumerator: [:foo, "bar", 2]:reverse_each>
2891
2958
  # a1 = e.each {|element| puts "#{element.class} #{element}" }
2892
2959
  #
2893
2960
  # Output:
2961
+ #
2894
2962
  # Integer 2
2895
2963
  # String bar
2896
2964
  # Symbol foo
@@ -2910,6 +2978,7 @@ class Array[unchecked out Elem] < Object
2910
2978
  #
2911
2979
  # When argument `object` is given but no block, returns the index of the last
2912
2980
  # such element found:
2981
+ #
2913
2982
  # a = [:foo, 'bar', 2, 'bar']
2914
2983
  # a.rindex('bar') # => 3
2915
2984
  #
@@ -2918,6 +2987,7 @@ class Array[unchecked out Elem] < Object
2918
2987
  # When a block is given but no argument, calls the block with each successive
2919
2988
  # element; returns the index of the last element for which the block returns a
2920
2989
  # truthy value:
2990
+ #
2921
2991
  # a = [:foo, 'bar', 2, 'bar']
2922
2992
  # a.rindex {|element| element == 'bar' } # => 3
2923
2993
  #
@@ -2946,33 +3016,39 @@ class Array[unchecked out Elem] < Object
2946
3016
  #
2947
3017
  # When no argument given, returns a new Array that is like `self`, except that
2948
3018
  # the first element has been rotated to the last position:
3019
+ #
2949
3020
  # a = [:foo, 'bar', 2, 'bar']
2950
3021
  # a1 = a.rotate
2951
3022
  # a1 # => ["bar", 2, "bar", :foo]
2952
3023
  #
2953
3024
  # When given a non-negative Integer `count`, returns a new Array with `count`
2954
3025
  # elements rotated from the beginning to the end:
3026
+ #
2955
3027
  # a = [:foo, 'bar', 2]
2956
3028
  # a1 = a.rotate(2)
2957
3029
  # a1 # => [2, :foo, "bar"]
2958
3030
  #
2959
3031
  # If `count` is large, uses `count % array.size` as the count:
3032
+ #
2960
3033
  # a = [:foo, 'bar', 2]
2961
3034
  # a1 = a.rotate(20)
2962
3035
  # a1 # => [2, :foo, "bar"]
2963
3036
  #
2964
3037
  # If `count` is zero, returns a copy of `self`, unmodified:
3038
+ #
2965
3039
  # a = [:foo, 'bar', 2]
2966
3040
  # a1 = a.rotate(0)
2967
3041
  # a1 # => [:foo, "bar", 2]
2968
3042
  #
2969
3043
  # When given a negative Integer `count`, rotates in the opposite direction, from
2970
3044
  # end to beginning:
3045
+ #
2971
3046
  # a = [:foo, 'bar', 2]
2972
3047
  # a1 = a.rotate(-2)
2973
3048
  # a1 # => ["bar", 2, :foo]
2974
3049
  #
2975
3050
  # If `count` is small (far from zero), uses `count % array.size` as the count:
3051
+ #
2976
3052
  # a = [:foo, 'bar', 2]
2977
3053
  # a1 = a.rotate(-5)
2978
3054
  # a1 # => ["bar", 2, :foo]
@@ -2988,32 +3064,38 @@ class Array[unchecked out Elem] < Object
2988
3064
  # `self`.
2989
3065
  #
2990
3066
  # When no argument given, rotates the first element to the last position:
3067
+ #
2991
3068
  # a = [:foo, 'bar', 2, 'bar']
2992
3069
  # a.rotate! # => ["bar", 2, "bar", :foo]
2993
3070
  #
2994
3071
  # When given a non-negative Integer `count`, rotates `count` elements from the
2995
3072
  # beginning to the end:
3073
+ #
2996
3074
  # a = [:foo, 'bar', 2]
2997
3075
  # a.rotate!(2)
2998
3076
  # a # => [2, :foo, "bar"]
2999
3077
  #
3000
3078
  # If `count` is large, uses `count % array.size` as the count:
3079
+ #
3001
3080
  # a = [:foo, 'bar', 2]
3002
3081
  # a.rotate!(20)
3003
3082
  # a # => [2, :foo, "bar"]
3004
3083
  #
3005
3084
  # If `count` is zero, returns `self` unmodified:
3085
+ #
3006
3086
  # a = [:foo, 'bar', 2]
3007
3087
  # a.rotate!(0)
3008
3088
  # a # => [:foo, "bar", 2]
3009
3089
  #
3010
3090
  # When given a negative Integer `count`, rotates in the opposite direction, from
3011
3091
  # end to beginning:
3092
+ #
3012
3093
  # a = [:foo, 'bar', 2]
3013
3094
  # a.rotate!(-2)
3014
3095
  # a # => ["bar", 2, :foo]
3015
3096
  #
3016
3097
  # If `count` is small (far from zero), uses `count % array.size` as the count:
3098
+ #
3017
3099
  # a = [:foo, 'bar', 2]
3018
3100
  # a.rotate!(-5)
3019
3101
  # a # => ["bar", 2, :foo]
@@ -3067,11 +3149,13 @@ class Array[unchecked out Elem] < Object
3067
3149
  # Calls the block, if given, with each element of `self`; returns a new Array
3068
3150
  # containing those elements of `self` for which the block returns a truthy
3069
3151
  # value:
3152
+ #
3070
3153
  # a = [:foo, 'bar', 2, :bam]
3071
3154
  # a1 = a.select {|element| element.to_s.start_with?('b') }
3072
3155
  # a1 # => ["bar", :bam]
3073
3156
  #
3074
3157
  # Returns a new Enumerator if no block given:
3158
+ #
3075
3159
  # a = [:foo, 'bar', 2, :bam]
3076
3160
  # a.select # => #<Enumerator: [:foo, "bar", 2, :bam]:select>
3077
3161
  #
@@ -3089,12 +3173,14 @@ class Array[unchecked out Elem] < Object
3089
3173
  # those elements for which the block returns `false` or `nil`.
3090
3174
  #
3091
3175
  # Returns `self` if any elements were removed:
3176
+ #
3092
3177
  # a = [:foo, 'bar', 2, :bam]
3093
3178
  # a.select! {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
3094
3179
  #
3095
3180
  # Returns `nil` if no elements were removed.
3096
3181
  #
3097
3182
  # Returns a new Enumerator if no block given:
3183
+ #
3098
3184
  # a = [:foo, 'bar', 2, :bam]
3099
3185
  # a.select! # => #<Enumerator: [:foo, "bar", 2, :bam]:select!>
3100
3186
  #
@@ -3111,6 +3197,7 @@ class Array[unchecked out Elem] < Object
3111
3197
  # Removes and returns leading elements.
3112
3198
  #
3113
3199
  # When no argument is given, removes and returns the first element:
3200
+ #
3114
3201
  # a = [:foo, 'bar', 2]
3115
3202
  # a.shift # => :foo
3116
3203
  # a # => ['bar', 2]
@@ -3119,12 +3206,14 @@ class Array[unchecked out Elem] < Object
3119
3206
  #
3120
3207
  # When positive Integer argument `n` is given, removes the first `n` elements;
3121
3208
  # returns those elements in a new Array:
3209
+ #
3122
3210
  # a = [:foo, 'bar', 2]
3123
3211
  # a.shift(2) # => [:foo, 'bar']
3124
3212
  # a # => [2]
3125
3213
  #
3126
3214
  # If `n` is as large as or larger than `self.length`, removes all elements;
3127
3215
  # returns those elements in a new Array:
3216
+ #
3128
3217
  # a = [:foo, 'bar', 2]
3129
3218
  # a.shift(3) # => [:foo, 'bar', 2]
3130
3219
  #
@@ -3173,12 +3262,14 @@ class Array[unchecked out Elem] < Object
3173
3262
  #
3174
3263
  # When a single Integer argument `index` is given, returns the element at offset
3175
3264
  # `index`:
3265
+ #
3176
3266
  # a = [:foo, 'bar', 2]
3177
3267
  # a[0] # => :foo
3178
3268
  # a[2] # => 2
3179
3269
  # a # => [:foo, "bar", 2]
3180
3270
  #
3181
3271
  # If `index` is negative, counts relative to the end of `self`:
3272
+ #
3182
3273
  # a = [:foo, 'bar', 2]
3183
3274
  # a[-1] # => 2
3184
3275
  # a[-2] # => "bar"
@@ -3187,12 +3278,14 @@ class Array[unchecked out Elem] < Object
3187
3278
  #
3188
3279
  # When two Integer arguments `start` and `length` are given, returns a new Array
3189
3280
  # of size `length` containing successive elements beginning at offset `start`:
3281
+ #
3190
3282
  # a = [:foo, 'bar', 2]
3191
3283
  # a[0, 2] # => [:foo, "bar"]
3192
3284
  # a[1, 2] # => ["bar", 2]
3193
3285
  #
3194
3286
  # If `start + length` is greater than `self.length`, returns all elements from
3195
3287
  # offset `start` to the end:
3288
+ #
3196
3289
  # a = [:foo, 'bar', 2]
3197
3290
  # a[0, 4] # => [:foo, "bar", 2]
3198
3291
  # a[1, 3] # => ["bar", 2]
@@ -3204,6 +3297,7 @@ class Array[unchecked out Elem] < Object
3204
3297
  #
3205
3298
  # When a single Range argument `range` is given, treats `range.min` as `start`
3206
3299
  # above and `range.size` as `length` above:
3300
+ #
3207
3301
  # a = [:foo, 'bar', 2]
3208
3302
  # a[0..1] # => [:foo, "bar"]
3209
3303
  # a[1..2] # => ["bar", 2]
@@ -3211,18 +3305,21 @@ class Array[unchecked out Elem] < Object
3211
3305
  # Special case: If `range.start == a.size`, returns a new empty Array.
3212
3306
  #
3213
3307
  # If `range.end` is negative, calculates the end index from the end:
3308
+ #
3214
3309
  # a = [:foo, 'bar', 2]
3215
3310
  # a[0..-1] # => [:foo, "bar", 2]
3216
3311
  # a[0..-2] # => [:foo, "bar"]
3217
3312
  # a[0..-3] # => [:foo]
3218
3313
  #
3219
3314
  # If `range.start` is negative, calculates the start index from the end:
3315
+ #
3220
3316
  # a = [:foo, 'bar', 2]
3221
3317
  # a[-1..2] # => [2]
3222
3318
  # a[-2..2] # => ["bar", 2]
3223
3319
  # a[-3..2] # => [:foo, "bar", 2]
3224
3320
  #
3225
3321
  # If `range.start` is larger than the array size, returns `nil`.
3322
+ #
3226
3323
  # a = [:foo, 'bar', 2]
3227
3324
  # a[4..1] # => nil
3228
3325
  # a[4..0] # => nil
@@ -3230,11 +3327,13 @@ class Array[unchecked out Elem] < Object
3230
3327
  #
3231
3328
  # When a single Enumerator::ArithmeticSequence argument `aseq` is given, returns
3232
3329
  # an Array of elements corresponding to the indexes produced by the sequence.
3330
+ #
3233
3331
  # a = ['--', 'data1', '--', 'data2', '--', 'data3']
3234
3332
  # a[(1..).step(2)] # => ["data1", "data2", "data3"]
3235
3333
  #
3236
3334
  # Unlike slicing with range, if the start or the end of the arithmetic sequence
3237
3335
  # is larger than array size, throws RangeError.
3336
+ #
3238
3337
  # a = ['--', 'data1', '--', 'data2', '--', 'data3']
3239
3338
  # a[(1..11).step(2)]
3240
3339
  # # RangeError (((1..11).step(2)) out of range)
@@ -3243,6 +3342,7 @@ class Array[unchecked out Elem] < Object
3243
3342
  #
3244
3343
  # If given a single argument, and its type is not one of the listed, tries to
3245
3344
  # convert it to Integer, and raises if it is impossible:
3345
+ #
3246
3346
  # a = [:foo, 'bar', 2]
3247
3347
  # # Raises TypeError (no implicit conversion of Symbol into Integer):
3248
3348
  # a[:foo]
@@ -3263,11 +3363,13 @@ class Array[unchecked out Elem] < Object
3263
3363
  #
3264
3364
  # When the only argument is an Integer `n`, removes and returns the *nth*
3265
3365
  # element in `self`:
3366
+ #
3266
3367
  # a = [:foo, 'bar', 2]
3267
3368
  # a.slice!(1) # => "bar"
3268
3369
  # a # => [:foo, 2]
3269
3370
  #
3270
3371
  # If `n` is negative, counts backwards from the end of `self`:
3372
+ #
3271
3373
  # a = [:foo, 'bar', 2]
3272
3374
  # a.slice!(-1) # => 2
3273
3375
  # a # => [:foo, "bar"]
@@ -3277,12 +3379,14 @@ class Array[unchecked out Elem] < Object
3277
3379
  # When the only arguments are Integers `start` and `length`, removes `length`
3278
3380
  # elements from `self` beginning at offset `start`; returns the deleted objects
3279
3381
  # in a new Array:
3382
+ #
3280
3383
  # a = [:foo, 'bar', 2]
3281
3384
  # a.slice!(0, 2) # => [:foo, "bar"]
3282
3385
  # a # => [2]
3283
3386
  #
3284
3387
  # If `start + length` exceeds the array size, removes and returns all elements
3285
3388
  # from offset `start` to the end:
3389
+ #
3286
3390
  # a = [:foo, 'bar', 2]
3287
3391
  # a.slice!(1, 50) # => ["bar", 2]
3288
3392
  # a # => [:foo]
@@ -3293,8 +3397,9 @@ class Array[unchecked out Elem] < Object
3293
3397
  #
3294
3398
  # When the only argument is a Range object `range`, treats `range.min` as
3295
3399
  # `start` above and `range.size` as `length` above:
3400
+ #
3296
3401
  # a = [:foo, 'bar', 2]
3297
- # a.slice!(1..2) # => ["bar", 2]
3402
+ # a.slice!(1..2) # => ["bar", 2]
3298
3403
  # a # => [:foo]
3299
3404
  #
3300
3405
  # If `range.start == a.size`, returns a new empty Array.
@@ -3302,12 +3407,14 @@ class Array[unchecked out Elem] < Object
3302
3407
  # If `range.start` is larger than the array size, returns `nil`.
3303
3408
  #
3304
3409
  # If `range.end` is negative, counts backwards from the end of the array:
3410
+ #
3305
3411
  # a = [:foo, 'bar', 2]
3306
3412
  # a.slice!(0..-2) # => [:foo, "bar"]
3307
3413
  # a # => [2]
3308
3414
  #
3309
3415
  # If `range.start` is negative, calculates the start index backwards from the
3310
3416
  # end of the array:
3417
+ #
3311
3418
  # a = [:foo, 'bar', 2]
3312
3419
  # a.slice!(-2..2) # => ["bar", 2]
3313
3420
  # a # => [:foo]
@@ -3324,6 +3431,7 @@ class Array[unchecked out Elem] < Object
3324
3431
  # Returns a new Array whose elements are those from `self`, sorted.
3325
3432
  #
3326
3433
  # With no block, compares elements using operator `<=>` (see Comparable):
3434
+ #
3327
3435
  # a = 'abcde'.split('').shuffle
3328
3436
  # a # => ["e", "b", "d", "a", "c"]
3329
3437
  # a1 = a.sort
@@ -3331,12 +3439,14 @@ class Array[unchecked out Elem] < Object
3331
3439
  #
3332
3440
  # With a block, calls the block with each element pair; for each element pair
3333
3441
  # `a` and `b`, the block should return an integer:
3442
+ #
3334
3443
  # * Negative when `b` is to follow `a`.
3335
3444
  # * Zero when `a` and `b` are equivalent.
3336
3445
  # * Positive when `a` is to follow `b`.
3337
3446
  #
3338
3447
  #
3339
3448
  # Example:
3449
+ #
3340
3450
  # a = 'abcde'.split('').shuffle
3341
3451
  # a # => ["e", "b", "d", "a", "c"]
3342
3452
  # a1 = a.sort {|a, b| a <=> b }
@@ -3346,6 +3456,7 @@ class Array[unchecked out Elem] < Object
3346
3456
  #
3347
3457
  # When the block returns zero, the order for `a` and `b` is indeterminate, and
3348
3458
  # may be unstable:
3459
+ #
3349
3460
  # a = 'abcde'.split('').shuffle
3350
3461
  # a # => ["e", "b", "d", "a", "c"]
3351
3462
  # a1 = a.sort {|a, b| 0 }
@@ -3364,6 +3475,7 @@ class Array[unchecked out Elem] < Object
3364
3475
  # Returns `self` with its elements sorted in place.
3365
3476
  #
3366
3477
  # With no block, compares elements using operator `<=>` (see Comparable):
3478
+ #
3367
3479
  # a = 'abcde'.split('').shuffle
3368
3480
  # a # => ["e", "b", "d", "a", "c"]
3369
3481
  # a.sort!
@@ -3371,12 +3483,14 @@ class Array[unchecked out Elem] < Object
3371
3483
  #
3372
3484
  # With a block, calls the block with each element pair; for each element pair
3373
3485
  # `a` and `b`, the block should return an integer:
3486
+ #
3374
3487
  # * Negative when `b` is to follow `a`.
3375
3488
  # * Zero when `a` and `b` are equivalent.
3376
3489
  # * Positive when `a` is to follow `b`.
3377
3490
  #
3378
3491
  #
3379
3492
  # Example:
3493
+ #
3380
3494
  # a = 'abcde'.split('').shuffle
3381
3495
  # a # => ["e", "b", "d", "a", "c"]
3382
3496
  # a.sort! {|a, b| a <=> b }
@@ -3386,6 +3500,7 @@ class Array[unchecked out Elem] < Object
3386
3500
  #
3387
3501
  # When the block returns zero, the order for `a` and `b` is indeterminate, and
3388
3502
  # may be unstable:
3503
+ #
3389
3504
  # a = 'abcde'.split('').shuffle
3390
3505
  # a # => ["e", "b", "d", "a", "c"]
3391
3506
  # a.sort! {|a, b| 0 }
@@ -3409,6 +3524,7 @@ class Array[unchecked out Elem] < Object
3409
3524
  # be unstable.
3410
3525
  #
3411
3526
  # This example sorts strings based on their sizes:
3527
+ #
3412
3528
  # a = ['aaaa', 'bbb', 'cc', 'd']
3413
3529
  # a.sort_by! {|element| element.size }
3414
3530
  # a # => ["d", "cc", "bbb", "aaaa"]
@@ -3427,6 +3543,7 @@ class Array[unchecked out Elem] < Object
3427
3543
  # - array.sum(init = 0) {|element| ... } -> object
3428
3544
  # -->
3429
3545
  # When no block is given, returns the object equivalent to:
3546
+ #
3430
3547
  # sum = init
3431
3548
  # array.each {|element| sum += element }
3432
3549
  # sum
@@ -3434,22 +3551,26 @@ class Array[unchecked out Elem] < Object
3434
3551
  # For example, `[e1, e2, e3].sum` returns `init + e1 + e2 + e3`.
3435
3552
  #
3436
3553
  # Examples:
3554
+ #
3437
3555
  # a = [0, 1, 2, 3]
3438
3556
  # a.sum # => 6
3439
3557
  # a.sum(100) # => 106
3440
3558
  #
3441
3559
  # The elements need not be numeric, but must be `+`-compatible with each other
3442
3560
  # and with `init`:
3561
+ #
3443
3562
  # a = ['abc', 'def', 'ghi']
3444
3563
  # a.sum('jkl') # => "jklabcdefghi"
3445
3564
  #
3446
3565
  # When a block is given, it is called with each element and the block's return
3447
3566
  # value (instead of the element itself) is used as the addend:
3567
+ #
3448
3568
  # a = ['zero', 1, :two]
3449
3569
  # s = a.sum('Coerced and concatenated: ') {|element| element.to_s }
3450
3570
  # s # => "Coerced and concatenated: zero1two"
3451
3571
  #
3452
3572
  # Notes:
3573
+ #
3453
3574
  # * Array#join and Array#flatten may be faster than Array#sum for an Array of
3454
3575
  # Strings or an Array of Arrays.
3455
3576
  # * Array#sum method may not respect method redefinition of "+" methods such
@@ -3466,6 +3587,7 @@ class Array[unchecked out Elem] < Object
3466
3587
  # non-negative Integer; does not modify `self`.
3467
3588
  #
3468
3589
  # Examples:
3590
+ #
3469
3591
  # a = [0, 1, 2, 3, 4, 5]
3470
3592
  # a.take(1) # => [0]
3471
3593
  # a.take(2) # => [0, 1]
@@ -3485,12 +3607,14 @@ class Array[unchecked out Elem] < Object
3485
3607
  # With a block given, calls the block with each successive element of `self`;
3486
3608
  # stops if the block returns `false` or `nil`; returns a new Array containing
3487
3609
  # those elements for which the block returned a truthy value:
3610
+ #
3488
3611
  # a = [0, 1, 2, 3, 4, 5]
3489
3612
  # a.take_while {|element| element < 3 } # => [0, 1, 2]
3490
3613
  # a.take_while {|element| true } # => [0, 1, 2, 3, 4, 5]
3491
3614
  # a # => [0, 1, 2, 3, 4, 5]
3492
3615
  #
3493
3616
  # With no block given, returns a new Enumerator:
3617
+ #
3494
3618
  # [0, 1].take_while # => #<Enumerator: [0, 1]:take_while>
3495
3619
  #
3496
3620
  def take_while: () { (Elem obj) -> boolish } -> ::Array[Elem]
@@ -3501,10 +3625,12 @@ class Array[unchecked out Elem] < Object
3501
3625
  # - to_a -> self or new_array
3502
3626
  # -->
3503
3627
  # When `self` is an instance of Array, returns `self`:
3628
+ #
3504
3629
  # a = [:foo, 'bar', 2]
3505
3630
  # a.to_a # => [:foo, "bar", 2]
3506
3631
  #
3507
3632
  # Otherwise, returns a new Array containing the elements of `self`:
3633
+ #
3508
3634
  # class MyArray < Array; end
3509
3635
  # a = MyArray.new(['foo', 'bar', 'two'])
3510
3636
  # a.instance_of?(Array) # => false
@@ -3533,12 +3659,14 @@ class Array[unchecked out Elem] < Object
3533
3659
  # When a block is given, calls the block with each array element; the block must
3534
3660
  # return a 2-element Array whose two elements form a key-value pair in the
3535
3661
  # returned Hash:
3662
+ #
3536
3663
  # a = ['foo', :bar, 1, [2, 3], {baz: 4}]
3537
3664
  # h = a.to_h {|item| [item, item] }
3538
3665
  # h # => {"foo"=>"foo", :bar=>:bar, 1=>1, [2, 3]=>[2, 3], {:baz=>4}=>{:baz=>4}}
3539
3666
  #
3540
3667
  # When no block is given, `self` must be an Array of 2-element sub-arrays, each
3541
3668
  # sub-array is formed into a key-value pair in the new Hash:
3669
+ #
3542
3670
  # [].to_h # => {}
3543
3671
  # a = [['foo', 'zero'], ['bar', 'one'], ['baz', 'two']]
3544
3672
  # h = a.to_h
@@ -3550,6 +3678,7 @@ class Array[unchecked out Elem] < Object
3550
3678
  # <!-- rdoc-file=array.c -->
3551
3679
  # Returns the new String formed by calling method `#inspect` on each array
3552
3680
  # element:
3681
+ #
3553
3682
  # a = [:foo, 'bar', 2]
3554
3683
  # a.inspect # => "[:foo, \"bar\", 2]"
3555
3684
  #
@@ -3563,6 +3692,7 @@ class Array[unchecked out Elem] < Object
3563
3692
  # -->
3564
3693
  # Transposes the rows and columns in an Array of Arrays; the nested Arrays must
3565
3694
  # all be the same size:
3695
+ #
3566
3696
  # a = [[:a0, :a1], [:b0, :b1], [:c0, :c1]]
3567
3697
  # a.transpose # => [[:a0, :b0, :c0], [:a1, :b1, :c1]]
3568
3698
  #
@@ -3575,6 +3705,7 @@ class Array[unchecked out Elem] < Object
3575
3705
  # Returns a new Array that is the union of `self` and all given Arrays
3576
3706
  # `other_arrays`; duplicates are removed; order is preserved; items are
3577
3707
  # compared using `eql?`:
3708
+ #
3578
3709
  # [0, 1, 2, 3].union([4, 5], [6, 7]) # => [0, 1, 2, 3, 4, 5, 6, 7]
3579
3710
  # [0, 1, 1].union([2, 1], [3, 1]) # => [0, 1, 2, 3]
3580
3711
  # [0, 1, 2, 3].union([3, 2], [1, 0]) # => [0, 1, 2, 3]
@@ -3594,13 +3725,15 @@ class Array[unchecked out Elem] < Object
3594
3725
  # duplicates, the first occurrence always being retained.
3595
3726
  #
3596
3727
  # With no block given, identifies and omits duplicates using method `eql?` to
3597
- # compare.
3728
+ # compare:
3729
+ #
3598
3730
  # a = [0, 0, 1, 1, 2, 2]
3599
3731
  # a.uniq # => [0, 1, 2]
3600
3732
  #
3601
3733
  # With a block given, calls the block for each element; identifies (using method
3602
3734
  # `eql?`) and omits duplicate values, that is, those elements for which the
3603
3735
  # block returns the same value:
3736
+ #
3604
3737
  # a = ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
3605
3738
  # a.uniq {|element| element.size } # => ["a", "aa", "aaa"]
3606
3739
  #
@@ -3619,6 +3752,7 @@ class Array[unchecked out Elem] < Object
3619
3752
  # compare.
3620
3753
  #
3621
3754
  # Returns `self` if any elements removed:
3755
+ #
3622
3756
  # a = [0, 0, 1, 1, 2, 2]
3623
3757
  # a.uniq! # => [0, 1, 2]
3624
3758
  #
@@ -3628,6 +3762,7 @@ class Array[unchecked out Elem] < Object
3628
3762
  # `eql?`) and removes elements for which the block returns duplicate values.
3629
3763
  #
3630
3764
  # Returns `self` if any elements removed:
3765
+ #
3631
3766
  # a = ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
3632
3767
  # a.uniq! {|element| element.size } # => ['a', 'aa', 'aaa']
3633
3768
  #
@@ -3641,6 +3776,7 @@ class Array[unchecked out Elem] < Object
3641
3776
  # - array.unshift(*objects) -> self
3642
3777
  # -->
3643
3778
  # Prepends the given `objects` to `self`:
3779
+ #
3644
3780
  # a = [:foo, 'bar', 2]
3645
3781
  # a.unshift(:bam, :bat) # => [:bam, :bat, :foo, "bar", 2]
3646
3782
  #
@@ -3658,30 +3794,36 @@ class Array[unchecked out Elem] < Object
3658
3794
  # Integer or Range `indexes`.
3659
3795
  #
3660
3796
  # For each positive `index`, returns the element at offset `index`:
3797
+ #
3661
3798
  # a = [:foo, 'bar', 2]
3662
3799
  # a.values_at(0, 2) # => [:foo, 2]
3663
3800
  # a.values_at(0..1) # => [:foo, "bar"]
3664
3801
  #
3665
3802
  # The given `indexes` may be in any order, and may repeat:
3803
+ #
3666
3804
  # a = [:foo, 'bar', 2]
3667
3805
  # a.values_at(2, 0, 1, 0, 2) # => [2, :foo, "bar", :foo, 2]
3668
3806
  # a.values_at(1, 0..2) # => ["bar", :foo, "bar", 2]
3669
3807
  #
3670
3808
  # Assigns `nil` for an `index` that is too large:
3809
+ #
3671
3810
  # a = [:foo, 'bar', 2]
3672
3811
  # a.values_at(0, 3, 1, 3) # => [:foo, nil, "bar", nil]
3673
3812
  #
3674
3813
  # Returns a new empty Array if no arguments given.
3675
3814
  #
3676
3815
  # For each negative `index`, counts backward from the end of the array:
3816
+ #
3677
3817
  # a = [:foo, 'bar', 2]
3678
3818
  # a.values_at(-1, -3) # => [2, :foo]
3679
3819
  #
3680
3820
  # Assigns `nil` for an `index` that is too small:
3821
+ #
3681
3822
  # a = [:foo, 'bar', 2]
3682
3823
  # a.values_at(0, -5, 1, -6, 2) # => [:foo, nil, "bar", nil, 2]
3683
3824
  #
3684
3825
  # The given `indexes` may have a mixture of signs:
3826
+ #
3685
3827
  # a = [:foo, 'bar', 2]
3686
3828
  # a.values_at(0, -2, 1, -1) # => [:foo, "bar", "bar", 2]
3687
3829
  #
@@ -3697,11 +3839,13 @@ class Array[unchecked out Elem] < Object
3697
3839
  #
3698
3840
  # Each nested array `new_array[n]` is of size `other_arrays.size+1`, and
3699
3841
  # contains:
3842
+ #
3700
3843
  # * The *nth* element of `self`.
3701
3844
  # * The *nth* element of each of the `other_arrays`.
3702
3845
  #
3703
3846
  #
3704
3847
  # If all `other_arrays` and `self` are the same size:
3848
+ #
3705
3849
  # a = [:a0, :a1, :a2, :a3]
3706
3850
  # b = [:b0, :b1, :b2, :b3]
3707
3851
  # c = [:c0, :c1, :c2, :c3]
@@ -3710,6 +3854,7 @@ class Array[unchecked out Elem] < Object
3710
3854
  #
3711
3855
  # If any array in `other_arrays` is smaller than `self`, fills to `self.size`
3712
3856
  # with `nil`:
3857
+ #
3713
3858
  # a = [:a0, :a1, :a2, :a3]
3714
3859
  # b = [:b0, :b1, :b2]
3715
3860
  # c = [:c0, :c1]
@@ -3718,6 +3863,7 @@ class Array[unchecked out Elem] < Object
3718
3863
  #
3719
3864
  # If any array in `other_arrays` is larger than `self`, its trailing elements
3720
3865
  # are ignored:
3866
+ #
3721
3867
  # a = [:a0, :a1, :a2, :a3]
3722
3868
  # b = [:b0, :b1, :b2, :b3, :b4]
3723
3869
  # c = [:c0, :c1, :c2, :c3, :c4, :c5]
@@ -3725,22 +3871,24 @@ class Array[unchecked out Elem] < Object
3725
3871
  # d # => [[:a0, :b0, :c0], [:a1, :b1, :c1], [:a2, :b2, :c2], [:a3, :b3, :c3]]
3726
3872
  #
3727
3873
  # When a block is given, calls the block with each of the sub-arrays (formed as
3728
- # above); returns nil
3874
+ # above); returns `nil`:
3875
+ #
3729
3876
  # a = [:a0, :a1, :a2, :a3]
3730
3877
  # b = [:b0, :b1, :b2, :b3]
3731
3878
  # c = [:c0, :c1, :c2, :c3]
3732
3879
  # a.zip(b, c) {|sub_array| p sub_array} # => nil
3733
3880
  #
3734
3881
  # Output:
3882
+ #
3735
3883
  # [:a0, :b0, :c0]
3736
3884
  # [:a1, :b1, :c1]
3737
3885
  # [:a2, :b2, :c2]
3738
3886
  # [:a3, :b3, :c3]
3739
3887
  #
3740
- def zip: [U] (::Array[U] arg) -> ::Array[[ Elem, U? ]]
3741
- | (::Array[untyped] arg, *::Array[untyped] args) -> ::Array[::Array[untyped]]
3742
- | [U] (::Array[U] arg) { ([ Elem, U? ]) -> void } -> void
3743
- | (::Array[untyped] arg, *::Array[untyped] args) { (::Array[untyped]) -> void } -> void
3888
+ def zip: [U] (_Each[U] arg) -> Array[[ Elem, U? ]]
3889
+ | (_Each[untyped] arg, *_Each[untyped] args) -> Array[Array[untyped]]
3890
+ | [U] (_Each[U] arg) { ([ Elem, U? ]) -> void } -> nil
3891
+ | (_Each[untyped] arg, *_Each[untyped] args) { (Array[untyped]) -> void } -> nil
3744
3892
 
3745
3893
  # <!--
3746
3894
  # rdoc-file=array.c
@@ -3748,6 +3896,7 @@ class Array[unchecked out Elem] < Object
3748
3896
  # -->
3749
3897
  # Returns the union of `array` and Array `other_array`; duplicates are removed;
3750
3898
  # order is preserved; items are compared using `eql?`:
3899
+ #
3751
3900
  # [0, 1] | [2, 3] # => [0, 1, 2, 3]
3752
3901
  # [0, 1, 1] | [2, 2, 3] # => [0, 1, 2, 3]
3753
3902
  # [0, 1, 2] | [3, 2, 1, 0] # => [0, 1, 2, 3]
@@ -3764,6 +3913,7 @@ class Array[unchecked out Elem] < Object
3764
3913
  # -->
3765
3914
  # Replaces the content of `self` with the content of `other_array`; returns
3766
3915
  # `self`:
3916
+ #
3767
3917
  # a = [:foo, 'bar', 2]
3768
3918
  # a.replace(['foo', :bar, 3]) # => ["foo", :bar, 3]
3769
3919
  #