Skip to content

Commit 31a4a54

Browse files
committed
finished array
1 parent cd59fe4 commit 31a4a54

2 files changed

Lines changed: 282 additions & 84 deletions

File tree

core/array.rbs

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ class Array[unchecked out E]
723723
#
724724
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
725725
#
726-
def -: (array[untyped] other_array) -> Array[E] # TODO: `where E: _Eql?[T]`
726+
def -: (array[untyped] other_array) -> Array[E] # TODO: `where E: _Eql?[T]`
727727

728728
# <!--
729729
# rdoc-file=array.c
@@ -1233,9 +1233,8 @@ class Array[unchecked out E]
12331233
#
12341234
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
12351235
#
1236-
def bsearch: () -> ::Enumerator[E, E?]
1237-
| () { (E) -> (true | false) } -> E?
1238-
| () { (E) -> ::Integer } -> E?
1236+
def bsearch: () { (E element) -> (Numeric | bool?) } -> E?
1237+
| () -> Enumerator[E, E?]
12391238

12401239
# <!--
12411240
# rdoc-file=array.c
@@ -1249,8 +1248,8 @@ class Array[unchecked out E]
12491248
#
12501249
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
12511250
#
1252-
def bsearch_index: () { (E) -> (true | false) } -> ::Integer?
1253-
| () { (E) -> ::Integer } -> ::Integer?
1251+
def bsearch_index: () { (E element) -> (Numeric | bool?) } -> Integer?
1252+
| () -> Enumerator[E, Integer?]
12541253

12551254
# <!--
12561255
# rdoc-file=array.c
@@ -1284,8 +1283,8 @@ class Array[unchecked out E]
12841283
# Related: #collect!; see also [Methods for
12851284
# Converting](rdoc-ref:Array@Methods+for+Converting).
12861285
#
1287-
def collect: [U] () { (E item) -> U } -> ::Array[U]
1288-
| () -> ::Enumerator[E, ::Array[untyped]]
1286+
def collect: [T] () { (E item) -> T } -> Array[T]
1287+
| () -> Enumerator[E, Array[untyped]]
12891288

12901289
# <!--
12911290
# rdoc-file=array.c
@@ -1305,8 +1304,8 @@ class Array[unchecked out E]
13051304
# Related: #collect; see also [Methods for
13061305
# Converting](rdoc-ref:Array@Methods+for+Converting).
13071306
#
1308-
def collect!: () { (E item) -> E } -> self
1309-
| () -> ::Enumerator[E, self]
1307+
def collect!: () { (E element) -> E } -> self
1308+
| () -> Enumerator[E, self]
13101309

13111310
# <!--
13121311
# rdoc-file=array.c
@@ -1350,8 +1349,8 @@ class Array[unchecked out E]
13501349
# Related: Array#permutation; see also [Methods for
13511350
# Iterating](rdoc-ref:Array@Methods+for+Iterating).
13521351
#
1353-
def combination: (int n) { (::Array[E]) -> void } -> self
1354-
| (int n) -> ::Enumerator[::Array[E], self]
1352+
def combination: (int count) { (Array[E] combination) -> void } -> self
1353+
| (int count) -> Enumerator[Array[E], self]
13551354

13561355
# <!--
13571356
# rdoc-file=array.c
@@ -1461,8 +1460,8 @@ class Array[unchecked out E]
14611460
#
14621461
# Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
14631462
#
1464-
def cycle: (?int? n) { (E) -> void } -> nil
1465-
| (?int? n) -> ::Enumerator[E, nil]
1463+
def cycle: (?int? n) { (E element) -> void } -> nil
1464+
| (?int? n) -> Enumerator[E, nil]
14661465

14671466
# <!--
14681467
# rdoc-file=array.c
@@ -1555,7 +1554,7 @@ class Array[unchecked out E]
15551554
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
15561555
#
15571556
def delete_if: () { (E item) -> boolish } -> self
1558-
| () -> ::Enumerator[E, self]
1557+
| () -> Enumerator[E, self]
15591558

15601559
# <!--
15611560
# rdoc-file=array.c
@@ -1634,8 +1633,8 @@ class Array[unchecked out E]
16341633
#
16351634
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
16361635
#
1637-
def drop_while: () { (E obj) -> boolish } -> ::Array[E]
1638-
| () -> ::Enumerator[E, ::Array[E]]
1636+
def drop_while: () { (E element) -> boolish } -> Array[E]
1637+
| () -> Enumerator[E, Array[E]]
16391638

16401639
# <!--
16411640
# rdoc-file=array.c
@@ -1668,8 +1667,8 @@ class Array[unchecked out E]
16681667
#
16691668
# Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
16701669
#
1671-
def each: () -> ::Enumerator[E, self]
1672-
| () { (E item) -> void } -> self
1670+
def each: () { (E element) -> void } -> self
1671+
| () -> Enumerator[E, self]
16731672

16741673
# <!--
16751674
# rdoc-file=array.c
@@ -1703,8 +1702,8 @@ class Array[unchecked out E]
17031702
#
17041703
# Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
17051704
#
1706-
def each_index: () { (::Integer index) -> void } -> self
1707-
| () -> ::Enumerator[::Integer, self]
1705+
def each_index: () { (Integer index) -> void } -> self
1706+
| () -> Enumerator[Integer, self]
17081707

17091708
# <!--
17101709
# rdoc-file=array.c
@@ -1996,8 +1995,8 @@ class Array[unchecked out E]
19961995
#
19971996
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
19981997
#
1999-
def fill: (E obj, ?int? start, ?int? length) -> self
2000-
| (E obj, range[int?] range) -> self
1998+
def fill: (E object, ?int? start, ?int? length) -> self
1999+
| (E object, range[int?] range) -> self
20012000
| (?int? start, ?int? length) { (Integer index) -> E } -> self
20022001
| (range[int?] range) { (Integer index) -> E } -> self
20032002

@@ -2014,8 +2013,7 @@ class Array[unchecked out E]
20142013
#
20152014
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
20162015
#
2017-
def filter: () { (E item) -> boolish } -> ::Array[E]
2018-
| () -> ::Enumerator[E, ::Array[E]]
2016+
alias filter select
20192017

20202018
# <!-- rdoc-file=array.c -->
20212019
# With a block given, calls the block with each element of `self`; removes from
@@ -2032,8 +2030,7 @@ class Array[unchecked out E]
20322030
#
20332031
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
20342032
#
2035-
def filter!: () { (E item) -> boolish } -> self?
2036-
| () -> ::Enumerator[E, self?]
2033+
alias filter! select!
20372034

20382035
# <!--
20392036
# rdoc-file=array.c
@@ -2055,9 +2052,9 @@ class Array[unchecked out E]
20552052
# With no block given, returns an Enumerator.
20562053
#
20572054
def find: () { (E) -> boolish } -> E?
2058-
| () -> ::Enumerator[E, E?]
2059-
| [T] (Enumerable::_NotFound[T] ifnone) { (E) -> boolish } -> (E | T)
2060-
| [T] (Enumerable::_NotFound[T] ifnone) -> ::Enumerator[E, E | T]
2055+
| () -> Enumerator[E, E?]
2056+
| [T] (Enumerable::_NotFound[T]? ifnone) { (E) -> boolish } -> (E | T)
2057+
| [T] (Enumerable::_NotFound[T]? ifnone) -> Enumerator[E, E | T]
20612058

20622059
# <!--
20632060
# rdoc-file=array.c
@@ -2090,9 +2087,9 @@ class Array[unchecked out E]
20902087
#
20912088
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
20922089
#
2093-
def find_index: (untyped obj) -> ::Integer?
2094-
| () { (E item) -> boolish } -> ::Integer?
2095-
| () -> ::Enumerator[E, ::Integer?]
2090+
def find_index: (untyped object) -> Integer? # TODO: _Equal
2091+
| () { (E element) -> boolish } -> Integer?
2092+
| () -> Enumerator[E, Integer?]
20962093

20972094
# <!--
20982095
# rdoc-file=array.rb
@@ -2387,8 +2384,8 @@ class Array[unchecked out E]
23872384
#
23882385
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
23892386
#
2390-
def keep_if: () { (E item) -> boolish } -> self
2391-
| () -> ::Enumerator[E, self]
2387+
def keep_if: () { (E element) -> boolish } -> self
2388+
| () -> Enumerator[E, self]
23922389

23932390
# <!--
23942391
# rdoc-file=array.rb
@@ -2430,7 +2427,7 @@ class Array[unchecked out E]
24302427
#
24312428
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
24322429
#
2433-
def length: () -> ::Integer
2430+
def length: () -> Integer
24342431

24352432
# <!-- rdoc-file=array.c -->
24362433
# With a block given, calls the block with each element of `self`; returns a new
@@ -2713,8 +2710,8 @@ class Array[unchecked out E]
27132710
#
27142711
# Related: [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
27152712
#
2716-
def permutation: (?int n) -> ::Enumerator[::Array[E], ::Array[E]]
2717-
| (?int n) { (::Array[E] p) -> void } -> ::Array[E]
2713+
def permutation: (?int? count) { (Array[E] permutation) -> void } -> self
2714+
| (?int? count) -> Enumerator[Array[E], self]
27182715

27192716
# <!--
27202717
# rdoc-file=array.c
@@ -2896,7 +2893,7 @@ class Array[unchecked out E]
28962893
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
28972894
#
28982895
def reject!: () { (E item) -> boolish } -> self?
2899-
| () -> ::Enumerator[E, self?]
2896+
| () -> Enumerator[E, self?]
29002897

29012898
# <!--
29022899
# rdoc-file=array.c
@@ -2935,8 +2932,8 @@ class Array[unchecked out E]
29352932
#
29362933
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
29372934
#
2938-
def repeated_combination: (int n) { (::Array[E] c) -> void } -> self
2939-
| (int n) -> ::Enumerator[::Array[E], self]
2935+
def repeated_combination: (int size) { (Array[E] combination) -> void } -> self
2936+
| (int size) -> Enumerator[Array[E], self]
29402937

29412938
# <!--
29422939
# rdoc-file=array.c
@@ -2975,8 +2972,8 @@ class Array[unchecked out E]
29752972
#
29762973
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
29772974
#
2978-
def repeated_permutation: (int n) { (::Array[E] p) -> void } -> self
2979-
| (int n) -> ::Enumerator[::Array[E], self]
2975+
def repeated_permutation: (int size) { (Array[E] permutation) -> void } -> self
2976+
| (int size) -> Enumerator[Array[E], self]
29802977

29812978
# <!-- rdoc-file=array.c -->
29822979
# Replaces the elements of `self` with the elements of `other_array`, which must
@@ -3039,8 +3036,8 @@ class Array[unchecked out E]
30393036
#
30403037
# Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
30413038
#
3042-
def reverse_each: () { (E item) -> void } -> self
3043-
| () -> ::Enumerator[E, self]
3039+
def reverse_each: () { (E element) -> void } -> self
3040+
| () -> Enumerator[E, self]
30443041

30453042
# <!--
30463043
# rdoc-file=array.c
@@ -3063,9 +3060,9 @@ class Array[unchecked out E]
30633060
# With no block given, returns an Enumerator.
30643061
#
30653062
def rfind: () { (E) -> boolish } -> E?
3066-
| () -> ::Enumerator[E, E?]
3067-
| [T] (Enumerable::_NotFound[T] ifnone) { (E) -> boolish } -> (E | T)
3068-
| [T] (Enumerable::_NotFound[T] ifnone) -> ::Enumerator[E, E | T]
3063+
| () -> Enumerator[E, E?]
3064+
| [T] (Enumerable::_NotFound[T]? ifnone) { (E) -> boolish } -> (E | T)
3065+
| [T] (Enumerable::_NotFound[T]? ifnone) -> Enumerator[E, E | T]
30693066

30703067
# <!--
30713068
# rdoc-file=array.c
@@ -3096,9 +3093,9 @@ class Array[unchecked out E]
30963093
#
30973094
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
30983095
#
3099-
def rindex: (untyped obj) -> ::Integer?
3100-
| () { (E item) -> boolish } -> ::Integer?
3101-
| () -> ::Enumerator[E, ::Integer?]
3096+
def rindex: (untyped object) -> Integer? # TODO: _Equal
3097+
| () { (E element) -> boolish } -> Integer?
3098+
| () -> Enumerator[E, Integer?]
31023099

31033100
# <!--
31043101
# rdoc-file=array.c
@@ -3241,8 +3238,8 @@ class Array[unchecked out E]
32413238
#
32423239
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
32433240
#
3244-
def select: () { (E item) -> boolish } -> ::Array[E]
3245-
| () -> ::Enumerator[E, ::Array[E]]
3241+
def select: () { (E element) -> boolish } -> Array[E]
3242+
| () -> Enumerator[E, Array[E]]
32463243

32473244
# <!--
32483245
# rdoc-file=array.c
@@ -3265,8 +3262,8 @@ class Array[unchecked out E]
32653262
#
32663263
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
32673264
#
3268-
def select!: () { (E item) -> boolish } -> self?
3269-
| () -> ::Enumerator[E, self?]
3265+
def select!: () { (E element) -> boolish } -> self?
3266+
| () -> Enumerator[E, self?]
32703267

32713268
# <!--
32723269
# rdoc-file=array.c
@@ -3640,8 +3637,8 @@ class Array[unchecked out E]
36403637
#
36413638
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
36423639
#
3643-
def sort_by!: [U] () { (E obj) -> U } -> ::Array[E]
3644-
| () -> ::Enumerator[E, ::Array[E]]
3640+
def sort_by!: () { (E element) -> Comparable::_WithSpaceshipOperator } -> self # TODO: use RBS::Ops
3641+
| () -> Enumerator[E, self]
36453642

36463643
# <!--
36473644
# rdoc-file=array.c
@@ -3724,8 +3721,8 @@ class Array[unchecked out E]
37243721
#
37253722
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
37263723
#
3727-
def take_while: () { (E obj) -> boolish } -> ::Array[E]
3728-
| () -> ::Enumerator[E, ::Array[E]]
3724+
def take_while: () { (E element) -> boolish } -> Array[E]
3725+
| () -> Enumerator[E, Array[E]]
37293726

37303727
# <!--
37313728
# rdoc-file=array.c
@@ -4148,7 +4145,7 @@ end
41484145

41494146
%a{deprecated: Use Array::_Rand}
41504147
interface _Rand
4151-
def rand: (::Integer max) -> ::Integer
4148+
def rand: (Integer max) -> Integer
41524149
end
41534150

41544151
interface Array::_Pattern[T]

0 commit comments

Comments
 (0)