rbs 0.13.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +9 -5
- data/.gitignore +0 -1
- data/CHANGELOG.md +33 -1
- data/Gemfile +4 -0
- data/README.md +9 -3
- data/Rakefile +14 -1
- data/Steepfile +1 -1
- data/bin/annotate-with-rdoc +1 -1
- data/bin/setup +0 -2
- data/bin/test_runner.rb +15 -1
- data/{stdlib/builtin → core}/array.rbs +124 -120
- data/{stdlib/builtin → core}/basic_object.rbs +54 -54
- data/{stdlib/builtin → core}/binding.rbs +42 -42
- data/core/builtin.rbs +70 -0
- data/{stdlib/builtin → core}/class.rbs +33 -33
- data/{stdlib/builtin → core}/comparable.rbs +0 -0
- data/{stdlib/builtin → core}/complex.rbs +90 -90
- data/{stdlib/builtin → core}/constants.rbs +0 -0
- data/{stdlib/builtin → core}/data.rbs +0 -0
- data/{stdlib/builtin → core}/deprecated.rbs +0 -0
- data/{stdlib/builtin → core}/dir.rbs +1 -1
- data/{stdlib/builtin → core}/encoding.rbs +33 -33
- data/{stdlib/builtin → core}/enumerable.rbs +99 -92
- data/{stdlib/builtin → core}/enumerator.rbs +40 -40
- data/{stdlib/builtin → core}/errno.rbs +0 -0
- data/{stdlib/builtin → core}/errors.rbs +2 -2
- data/{stdlib/builtin → core}/exception.rbs +50 -50
- data/{stdlib/builtin → core}/false_class.rbs +6 -6
- data/{stdlib/builtin → core}/fiber.rbs +14 -14
- data/{stdlib/builtin → core}/fiber_error.rbs +1 -1
- data/{stdlib/builtin → core}/file.rbs +0 -0
- data/{stdlib/builtin → core}/file_test.rbs +0 -0
- data/{stdlib/builtin → core}/float.rbs +161 -161
- data/{stdlib/builtin → core}/gc.rbs +3 -3
- data/{stdlib/builtin → core}/hash.rbs +15 -15
- data/{stdlib/builtin → core}/integer.rbs +0 -0
- data/{stdlib/builtin → core}/io.rbs +89 -89
- data/{stdlib/builtin → core}/kernel.rbs +70 -154
- data/{stdlib/builtin → core}/marshal.rbs +0 -0
- data/{stdlib/builtin → core}/match_data.rbs +1 -1
- data/{stdlib/builtin → core}/math.rbs +0 -0
- data/{stdlib/builtin → core}/method.rbs +19 -19
- data/{stdlib/builtin → core}/module.rbs +13 -13
- data/{stdlib/builtin → core}/nil_class.rbs +20 -20
- data/{stdlib/builtin → core}/numeric.rbs +101 -101
- data/{stdlib/builtin → core}/object.rbs +173 -173
- data/{stdlib/builtin → core}/proc.rbs +91 -91
- data/{stdlib/builtin → core}/process.rbs +0 -0
- data/{stdlib/builtin → core}/random.rbs +1 -1
- data/{stdlib/builtin → core}/range.rbs +4 -6
- data/{stdlib/builtin → core}/rational.rbs +83 -83
- data/{stdlib/builtin → core}/rb_config.rbs +0 -0
- data/{stdlib/builtin → core}/regexp.rbs +0 -0
- data/{stdlib/builtin → core}/ruby_vm.rbs +0 -0
- data/{stdlib/builtin → core}/signal.rbs +7 -7
- data/{stdlib/builtin → core}/string.rbs +10 -10
- data/{stdlib/builtin → core}/string_io.rbs +8 -8
- data/{stdlib/builtin → core}/struct.rbs +2 -2
- data/{stdlib/builtin → core}/symbol.rbs +1 -1
- data/{stdlib/builtin → core}/thread.rbs +189 -189
- data/{stdlib/builtin → core}/thread_group.rbs +2 -2
- data/{stdlib/builtin → core}/time.rbs +0 -0
- data/{stdlib/builtin → core}/trace_point.rbs +0 -0
- data/{stdlib/builtin → core}/true_class.rbs +10 -10
- data/{stdlib/builtin → core}/unbound_method.rbs +0 -0
- data/{stdlib/builtin → core}/warning.rbs +1 -1
- data/docs/CONTRIBUTING.md +1 -0
- data/docs/repo.md +125 -0
- data/docs/syntax.md +50 -6
- data/goodcheck.yml +22 -5
- data/lib/rbs.rb +1 -0
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/cli.rb +105 -103
- data/lib/rbs/definition.rb +9 -4
- data/lib/rbs/definition_builder.rb +54 -22
- data/lib/rbs/environment.rb +1 -1
- data/lib/rbs/environment_loader.rb +79 -105
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/parser.rb +3153 -0
- data/lib/rbs/parser.y +25 -11
- data/lib/rbs/prototype/rb.rb +47 -9
- data/lib/rbs/prototype/runtime.rb +17 -7
- data/lib/rbs/repository.rb +121 -0
- data/lib/rbs/test/hook.rb +2 -0
- data/lib/rbs/test/setup.rb +5 -3
- data/lib/rbs/test/setup_helper.rb +4 -4
- data/lib/rbs/test/tester.rb +4 -1
- data/lib/rbs/test/type_check.rb +12 -6
- data/lib/rbs/type_name.rb +3 -2
- data/lib/rbs/variance_calculator.rb +1 -1
- data/lib/rbs/vendorer.rb +38 -16
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +1 -1
- data/sig/cli.rbs +58 -0
- data/sig/constant.rbs +2 -2
- data/sig/constant_table.rbs +11 -11
- data/sig/declarations.rbs +2 -2
- data/sig/definition.rbs +10 -5
- data/sig/definition_builder.rbs +4 -1
- data/sig/environment_loader.rbs +92 -46
- data/sig/members.rbs +2 -2
- data/sig/method_types.rbs +1 -1
- data/sig/namespace.rbs +4 -4
- data/sig/parser.rbs +25 -0
- data/sig/polyfill.rbs +42 -0
- data/sig/rbs.rbs +8 -0
- data/sig/repository.rbs +79 -0
- data/sig/substitution.rbs +3 -3
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +1 -1
- data/sig/vendorer.rbs +44 -0
- data/sig/writer.rbs +15 -15
- data/stdlib/abbrev/{abbrev.rbs → 0/abbrev.rbs} +0 -0
- data/stdlib/base64/{base64.rbs → 0/base64.rbs} +1 -1
- data/stdlib/benchmark/{benchmark.rbs → 0/benchmark.rbs} +2 -2
- data/stdlib/{bigdecimal/math → bigdecimal-math/0}/big_math.rbs +0 -0
- data/stdlib/bigdecimal/{big_decimal.rbs → 0/big_decimal.rbs} +0 -0
- data/stdlib/coverage/{coverage.rbs → 0/coverage.rbs} +2 -2
- data/stdlib/csv/{csv.rbs → 0/csv.rbs} +4 -4
- data/stdlib/date/{date.rbs → 0/date.rbs} +4 -4
- data/stdlib/date/{date_time.rbs → 0/date_time.rbs} +1 -1
- data/stdlib/dbm/0/dbm.rbs +277 -0
- data/stdlib/erb/{erb.rbs → 0/erb.rbs} +0 -0
- data/stdlib/fiber/{fiber.rbs → 0/fiber.rbs} +0 -0
- data/stdlib/find/{find.rbs → 0/find.rbs} +12 -12
- data/stdlib/forwardable/{forwardable.rbs → 0/forwardable.rbs} +0 -0
- data/stdlib/ipaddr/{ipaddr.rbs → 0/ipaddr.rbs} +0 -0
- data/stdlib/json/{json.rbs → 0/json.rbs} +0 -0
- data/stdlib/logger/{formatter.rbs → 0/formatter.rbs} +0 -0
- data/stdlib/logger/{log_device.rbs → 0/log_device.rbs} +1 -1
- data/stdlib/logger/{logger.rbs → 0/logger.rbs} +1 -1
- data/stdlib/logger/{period.rbs → 0/period.rbs} +0 -0
- data/stdlib/logger/{severity.rbs → 0/severity.rbs} +0 -0
- data/stdlib/mutex_m/{mutex_m.rbs → 0/mutex_m.rbs} +0 -0
- data/stdlib/pathname/{pathname.rbs → 0/pathname.rbs} +40 -40
- data/stdlib/prime/{integer-extension.rbs → 0/integer-extension.rbs} +0 -0
- data/stdlib/prime/{prime.rbs → 0/prime.rbs} +1 -1
- data/stdlib/pstore/0/pstore.rbs +287 -0
- data/stdlib/pty/{pty.rbs → 0/pty.rbs} +1 -1
- data/stdlib/securerandom/{securerandom.rbs → 0/securerandom.rbs} +0 -0
- data/stdlib/set/{set.rbs → 0/set.rbs} +10 -10
- data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +12 -12
- data/stdlib/tsort/0/cyclic.rbs +4 -0
- data/stdlib/tsort/0/interfaces.rbs +19 -0
- data/stdlib/tsort/0/tsort.rbs +363 -0
- data/stdlib/uri/{file.rbs → 0/file.rbs} +0 -0
- data/stdlib/uri/{generic.rbs → 0/generic.rbs} +1 -1
- data/stdlib/uri/{http.rbs → 0/http.rbs} +0 -0
- data/stdlib/uri/{https.rbs → 0/https.rbs} +0 -0
- data/stdlib/uri/{ldap.rbs → 0/ldap.rbs} +0 -0
- data/stdlib/uri/{ldaps.rbs → 0/ldaps.rbs} +0 -0
- data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
- data/steep/Gemfile.lock +9 -9
- metadata +104 -93
- data/stdlib/builtin/builtin.rbs +0 -42
File without changes
|
File without changes
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Encoding < Object
|
2
2
|
# Returns the hash of available encoding alias and original encoding name.
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Encoding.aliases
|
5
5
|
# #=> {"BINARY"=>"ASCII-8BIT", "ASCII"=>"US-ASCII", "ANSI_X3.4-1986"=>"US-ASCII",
|
6
6
|
# "SJIS"=>"Shift_JIS", "eucJP"=>"EUC-JP", "CP932"=>"Windows-31J"}
|
@@ -9,35 +9,35 @@ class Encoding < Object
|
|
9
9
|
def self.compatible?: (untyped obj1, untyped obj2) -> Encoding?
|
10
10
|
|
11
11
|
# Returns default external encoding.
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# The default external encoding is used by default for strings created
|
14
14
|
# from the following locations:
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# - CSV
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# - [File](https://ruby-doc.org/core-2.6.3/File.html) data read from
|
19
19
|
# disk
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# - SDBM
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# - StringIO
|
24
|
-
#
|
24
|
+
#
|
25
25
|
# - Zlib::GzipReader
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# - Zlib::GzipWriter
|
28
|
-
#
|
28
|
+
#
|
29
29
|
# - [String\#inspect](https://ruby-doc.org/core-2.6.3/String.html#method-i-inspect)
|
30
|
-
#
|
30
|
+
#
|
31
31
|
# - [Regexp\#inspect](https://ruby-doc.org/core-2.6.3/Regexp.html#method-i-inspect)
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# While strings created from these locations will have this encoding, the
|
34
34
|
# encoding may not be valid. Be sure to check
|
35
35
|
# [String\#valid\_encoding?](https://ruby-doc.org/core-2.6.3/String.html#method-i-valid_encoding-3F)
|
36
36
|
# .
|
37
|
-
#
|
37
|
+
#
|
38
38
|
# [File](https://ruby-doc.org/core-2.6.3/File.html) data written to disk
|
39
39
|
# will be transcoded to the default external encoding when written.
|
40
|
-
#
|
40
|
+
#
|
41
41
|
# The default external encoding is initialized by the locale or -E option.
|
42
42
|
def self.default_external: () -> Encoding
|
43
43
|
|
@@ -47,43 +47,43 @@ class Encoding < Object
|
|
47
47
|
# Returns default internal encoding. Strings will be transcoded to the
|
48
48
|
# default internal encoding in the following places if the default
|
49
49
|
# internal encoding is not nil:
|
50
|
-
#
|
50
|
+
#
|
51
51
|
# - CSV
|
52
|
-
#
|
52
|
+
#
|
53
53
|
# - Etc.sysconfdir and Etc.systmpdir
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# - [File](https://ruby-doc.org/core-2.6.3/File.html) data read from
|
56
56
|
# disk
|
57
|
-
#
|
57
|
+
#
|
58
58
|
# - [File](https://ruby-doc.org/core-2.6.3/File.html) names from
|
59
59
|
# [Dir](https://ruby-doc.org/core-2.6.3/Dir.html)
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# - [Integer\#chr](https://ruby-doc.org/core-2.6.3/Integer.html#method-i-chr)
|
62
|
-
#
|
62
|
+
#
|
63
63
|
# - [String\#inspect](https://ruby-doc.org/core-2.6.3/String.html#method-i-inspect)
|
64
64
|
# and
|
65
65
|
# [Regexp\#inspect](https://ruby-doc.org/core-2.6.3/Regexp.html#method-i-inspect)
|
66
|
-
#
|
66
|
+
#
|
67
67
|
# - Strings returned from Readline
|
68
|
-
#
|
68
|
+
#
|
69
69
|
# - Strings returned from SDBM
|
70
|
-
#
|
70
|
+
#
|
71
71
|
# - [Time\#zone](https://ruby-doc.org/core-2.6.3/Time.html#method-i-zone)
|
72
|
-
#
|
72
|
+
#
|
73
73
|
# - Values from [ENV](https://ruby-doc.org/core-2.6.3/ENV.html)
|
74
|
-
#
|
74
|
+
#
|
75
75
|
# - Values in ARGV including $PROGRAM\_NAME
|
76
|
-
#
|
76
|
+
#
|
77
77
|
# Additionally
|
78
78
|
# [String\#encode](https://ruby-doc.org/core-2.6.3/String.html#method-i-encode)
|
79
79
|
# and
|
80
80
|
# [String\#encode\!](https://ruby-doc.org/core-2.6.3/String.html#method-i-encode-21)
|
81
81
|
# use the default internal encoding if no encoding is given.
|
82
|
-
#
|
82
|
+
#
|
83
83
|
# The locale encoding (\_\_ENCODING\_\_), not
|
84
84
|
# [::default\_internal](Encoding.downloaded.ruby_doc#method-c-default_internal)
|
85
85
|
# , is used as the encoding of created strings.
|
86
|
-
#
|
86
|
+
#
|
87
87
|
# [::default\_internal](Encoding.downloaded.ruby_doc#method-c-default_internal)
|
88
88
|
# is initialized by the source file's internal\_encoding or -E option.
|
89
89
|
def self.default_internal: () -> Encoding?
|
@@ -97,7 +97,7 @@ class Encoding < Object
|
|
97
97
|
def self.list: () -> ::Array[Encoding]
|
98
98
|
|
99
99
|
# Returns the list of available encoding names.
|
100
|
-
#
|
100
|
+
#
|
101
101
|
# Encoding.name_list
|
102
102
|
# #=> ["US-ASCII", "ASCII-8BIT", "UTF-8",
|
103
103
|
# "ISO-8859-1", "Shift_JIS", "EUC-JP",
|
@@ -106,7 +106,7 @@ class Encoding < Object
|
|
106
106
|
def self.name_list: () -> ::Array[String]
|
107
107
|
|
108
108
|
# Returns whether ASCII-compatible or not.
|
109
|
-
#
|
109
|
+
#
|
110
110
|
# ```ruby
|
111
111
|
# Encoding::UTF_8.ascii_compatible? #=> true
|
112
112
|
# Encoding::UTF_16BE.ascii_compatible? #=> false
|
@@ -116,7 +116,7 @@ class Encoding < Object
|
|
116
116
|
# Returns true for dummy encodings. A dummy encoding is an encoding for
|
117
117
|
# which character handling is not properly implemented. It is used for
|
118
118
|
# stateful encodings.
|
119
|
-
#
|
119
|
+
#
|
120
120
|
# ```ruby
|
121
121
|
# Encoding::ISO_2022_JP.dummy? #=> true
|
122
122
|
# Encoding::UTF_8.dummy? #=> false
|
@@ -126,14 +126,14 @@ class Encoding < Object
|
|
126
126
|
def inspect: () -> String
|
127
127
|
|
128
128
|
# Returns the name of the encoding.
|
129
|
-
#
|
129
|
+
#
|
130
130
|
# ```ruby
|
131
131
|
# Encoding::UTF_8.name #=> "UTF-8"
|
132
132
|
# ```
|
133
133
|
def name: () -> String
|
134
134
|
|
135
135
|
# Returns the list of name and aliases of the encoding.
|
136
|
-
#
|
136
|
+
#
|
137
137
|
# ```ruby
|
138
138
|
# Encoding::WINDOWS_31J.names #=> ["Windows-31J", "CP932", "csWindows31J"]
|
139
139
|
# ```
|
@@ -142,7 +142,7 @@ class Encoding < Object
|
|
142
142
|
def replicate: (String name) -> Encoding
|
143
143
|
|
144
144
|
# Returns the name of the encoding.
|
145
|
-
#
|
145
|
+
#
|
146
146
|
# ```ruby
|
147
147
|
# Encoding::UTF_8.name #=> "UTF-8"
|
148
148
|
# ```
|
@@ -5,16 +5,16 @@
|
|
5
5
|
# objects in the collection must also implement a meaningful `<=>`
|
6
6
|
# operator, as these methods rely on an ordering between members of the
|
7
7
|
# collection.
|
8
|
-
module Enumerable[unchecked out Elem
|
8
|
+
module Enumerable[unchecked out Elem]: _Each[Elem]
|
9
9
|
# Passes each element of the collection to the given block. The method
|
10
10
|
# returns `true` if the block never returns `false` or `nil` . If the
|
11
11
|
# block is not given, Ruby adds an implicit block of `{ |obj| obj }` which
|
12
12
|
# will cause [all?](Enumerable.downloaded.ruby_doc#method-i-all-3F) to
|
13
13
|
# return `true` when none of the collection members are `false` or `nil` .
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# If instead a pattern is supplied, the method returns whether `pattern
|
16
16
|
# === element` for every collection member.
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# %w[ant bear cat].all? { |word| word.length >= 3 } #=> true
|
19
19
|
# %w[ant bear cat].all? { |word| word.length >= 4 } #=> false
|
20
20
|
# %w[ant bear cat].all?(/t/) #=> false
|
@@ -22,7 +22,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
22
22
|
# [nil, true, 99].all? #=> false
|
23
23
|
# [].all? #=> true
|
24
24
|
def all?: () -> bool
|
25
|
-
| () { (Elem
|
25
|
+
| () { (Elem) -> boolish } -> bool
|
26
26
|
|
27
27
|
# Passes each element of the collection to the given block. The method
|
28
28
|
# returns `true` if the block ever returns a value other than `false` or
|
@@ -30,10 +30,10 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
30
30
|
# |obj| obj }` that will cause
|
31
31
|
# [any?](Enumerable.downloaded.ruby_doc#method-i-any-3F) to return `true`
|
32
32
|
# if at least one of the collection members is not `false` or `nil` .
|
33
|
-
#
|
33
|
+
#
|
34
34
|
# If instead a pattern is supplied, the method returns whether `pattern
|
35
35
|
# === element` for any collection member.
|
36
|
-
#
|
36
|
+
#
|
37
37
|
# ```ruby
|
38
38
|
# %w[ant bear cat].any? { |word| word.length >= 3 } #=> true
|
39
39
|
# %w[ant bear cat].any? { |word| word.length >= 4 } #=> true
|
@@ -43,7 +43,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
43
43
|
# [].any? #=> false
|
44
44
|
# ```
|
45
45
|
def `any?`: () -> bool
|
46
|
-
| () { (Elem
|
46
|
+
| () { (Elem) -> boolish } -> bool
|
47
47
|
|
48
48
|
def collect: [U] () { (Elem arg0) -> U } -> ::Array[U]
|
49
49
|
| () -> ::Enumerator[Elem, ::Array[untyped]]
|
@@ -54,7 +54,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
54
54
|
# argument is given, the number of items in `enum` that are equal to
|
55
55
|
# `item` are counted. If a block is given, it counts the number of
|
56
56
|
# elements yielding a true value.
|
57
|
-
#
|
57
|
+
#
|
58
58
|
# ```ruby
|
59
59
|
# ary = [1, 2, 4, 2]
|
60
60
|
# ary.count #=> 4
|
@@ -62,54 +62,54 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
62
62
|
# ary.count{ |x| x%2==0 } #=> 3
|
63
63
|
# ```
|
64
64
|
def count: () -> Integer
|
65
|
-
| (?untyped
|
66
|
-
| () { (Elem
|
65
|
+
| (?untyped) -> Integer
|
66
|
+
| () { (Elem) -> boolish } -> Integer
|
67
67
|
|
68
68
|
def cycle: (?Integer n) { (Elem arg0) -> untyped } -> NilClass
|
69
|
-
| (?Integer n) -> ::Enumerator[Elem,
|
69
|
+
| (?Integer n) -> ::Enumerator[Elem, NilClass]
|
70
70
|
|
71
|
-
def detect: (?Proc ifnone) { (Elem
|
72
|
-
| (?Proc ifnone) -> ::Enumerator[Elem,
|
71
|
+
def detect: (?Proc ifnone) { (Elem) -> boolish } -> Elem?
|
72
|
+
| (?Proc ifnone) -> ::Enumerator[Elem, Elem?]
|
73
73
|
|
74
74
|
def drop: (Integer n) -> ::Array[Elem]
|
75
75
|
|
76
|
-
def drop_while: () { (Elem
|
77
|
-
| () -> ::Enumerator[Elem,
|
76
|
+
def drop_while: () { (Elem) -> boolish } -> ::Array[Elem]
|
77
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
78
78
|
|
79
79
|
def each_cons: (Integer n) { (::Array[Elem] arg0) -> untyped } -> NilClass
|
80
|
-
| (Integer n) -> ::Enumerator[::Array[Elem],
|
80
|
+
| (Integer n) -> ::Enumerator[::Array[Elem], NilClass]
|
81
81
|
|
82
|
-
def each_with_index: () { (Elem arg0, Integer arg1) -> untyped } ->
|
83
|
-
| () -> ::Enumerator[[ Elem, Integer ],
|
82
|
+
def each_with_index: () { (Elem arg0, Integer arg1) -> untyped } -> void
|
83
|
+
| () -> ::Enumerator[[ Elem, Integer ], void]
|
84
84
|
|
85
85
|
def each_with_object: [U] (U arg0) { (Elem arg0, untyped arg1) -> untyped } -> U
|
86
|
-
| [U] (U arg0) -> ::Enumerator[[ Elem, U ],
|
86
|
+
| [U] (U arg0) -> ::Enumerator[[ Elem, U ], U]
|
87
87
|
|
88
88
|
# Returns an array containing the items in *enum* .
|
89
|
-
#
|
89
|
+
#
|
90
90
|
# ```ruby
|
91
91
|
# (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7]
|
92
92
|
# { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]
|
93
|
-
#
|
93
|
+
#
|
94
94
|
# require 'prime'
|
95
95
|
# Prime.entries 10 #=> [2, 3, 5, 7]
|
96
96
|
# ```
|
97
97
|
def entries: () -> ::Array[Elem]
|
98
98
|
|
99
|
-
def find_all: () { (Elem
|
100
|
-
| () -> ::Enumerator[Elem,
|
99
|
+
def find_all: () { (Elem) -> boolish } -> ::Array[Elem]
|
100
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
101
101
|
|
102
102
|
alias select find_all
|
103
103
|
alias filter find_all
|
104
104
|
|
105
105
|
def find_index: (?untyped value) -> Integer?
|
106
|
-
| () { (Elem
|
107
|
-
| () -> ::Enumerator[Elem,
|
106
|
+
| () { (Elem) -> boolish } -> Integer?
|
107
|
+
| () -> ::Enumerator[Elem, Integer?]
|
108
108
|
|
109
109
|
# Returns the first element, or the first `n` elements, of the enumerable.
|
110
110
|
# If the enumerable is empty, the first form returns `nil`, and the
|
111
111
|
# second form returns an empty array.
|
112
|
-
#
|
112
|
+
#
|
113
113
|
# ```ruby
|
114
114
|
# %w[foo bar baz].first #=> "foo"
|
115
115
|
# %w[foo bar baz].first(2) #=> ["foo", "bar"]
|
@@ -118,7 +118,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
118
118
|
# [].first(10) #=> []
|
119
119
|
# ```
|
120
120
|
def first: () -> Elem?
|
121
|
-
| (
|
121
|
+
| (Integer n) -> ::Array[Elem]?
|
122
122
|
|
123
123
|
def grep: (untyped arg0) -> ::Array[Elem]
|
124
124
|
| [U] (untyped arg0) { (Elem arg0) -> U } -> ::Array[U]
|
@@ -127,7 +127,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
127
127
|
| [U] (untyped arg0) { (Elem arg0) -> U } -> ::Array[U]
|
128
128
|
|
129
129
|
def group_by: [U] () { (Elem arg0) -> U } -> ::Hash[U, ::Array[Elem]]
|
130
|
-
| () -> ::Enumerator[Elem,
|
130
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
131
131
|
|
132
132
|
def `include?`: (untyped arg0) -> bool
|
133
133
|
|
@@ -139,16 +139,16 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
139
139
|
# Returns the object in *enum* with the maximum value. The first form
|
140
140
|
# assumes all objects implement `Comparable` ; the second uses the block
|
141
141
|
# to return *a \<=\> b* .
|
142
|
-
#
|
142
|
+
#
|
143
143
|
# ```ruby
|
144
144
|
# a = %w(albatross dog horse)
|
145
145
|
# a.max #=> "horse"
|
146
146
|
# a.max { |a, b| a.length <=> b.length } #=> "albatross"
|
147
147
|
# ```
|
148
|
-
#
|
148
|
+
#
|
149
149
|
# If the `n` argument is given, maximum `n` elements are returned as an
|
150
150
|
# array, sorted in descending order.
|
151
|
-
#
|
151
|
+
#
|
152
152
|
# ```ruby
|
153
153
|
# a = %w[albatross dog horse]
|
154
154
|
# a.max(2) #=> ["horse", "dog"]
|
@@ -157,27 +157,27 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
157
157
|
# ```
|
158
158
|
def max: () -> Elem?
|
159
159
|
| () { (Elem arg0, Elem arg1) -> Integer } -> Elem?
|
160
|
-
| (
|
161
|
-
| (
|
160
|
+
| (Integer arg0) -> ::Array[Elem]
|
161
|
+
| (Integer arg0) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
|
162
162
|
|
163
|
-
def max_by: () -> ::Enumerator[Elem,
|
163
|
+
def max_by: () -> ::Enumerator[Elem, Elem?]
|
164
164
|
| () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> Elem?
|
165
|
-
| (
|
166
|
-
| (
|
165
|
+
| (Integer arg0) -> ::Enumerator[Elem, ::Array[Elem]]
|
166
|
+
| (Integer arg0) { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem]
|
167
167
|
|
168
168
|
# Returns the object in *enum* with the minimum value. The first form
|
169
169
|
# assumes all objects implement `Comparable` ; the second uses the block
|
170
170
|
# to return *a \<=\> b* .
|
171
|
-
#
|
171
|
+
#
|
172
172
|
# ```ruby
|
173
173
|
# a = %w(albatross dog horse)
|
174
174
|
# a.min #=> "albatross"
|
175
175
|
# a.min { |a, b| a.length <=> b.length } #=> "dog"
|
176
176
|
# ```
|
177
|
-
#
|
177
|
+
#
|
178
178
|
# If the `n` argument is given, minimum `n` elements are returned as a
|
179
179
|
# sorted array.
|
180
|
-
#
|
180
|
+
#
|
181
181
|
# ```ruby
|
182
182
|
# a = %w[albatross dog horse]
|
183
183
|
# a.min(2) #=> ["albatross", "dog"]
|
@@ -186,18 +186,18 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
186
186
|
# ```
|
187
187
|
def min: () -> Elem?
|
188
188
|
| () { (Elem arg0, Elem arg1) -> Integer } -> Elem?
|
189
|
-
| (
|
190
|
-
| (
|
189
|
+
| (Integer arg0) -> ::Array[Elem]
|
190
|
+
| (Integer arg0) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
|
191
191
|
|
192
|
-
def min_by: () -> ::Enumerator[Elem,
|
192
|
+
def min_by: () -> ::Enumerator[Elem, Elem?]
|
193
193
|
| () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> Elem?
|
194
|
-
| (
|
195
|
-
| (
|
194
|
+
| (Integer arg0) -> ::Enumerator[Elem, ::Array[Elem]]
|
195
|
+
| (Integer arg0) { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem]
|
196
196
|
|
197
197
|
# Returns a two element array which contains the minimum and the maximum
|
198
198
|
# value in the enumerable. The first form assumes all objects implement
|
199
199
|
# `Comparable` ; the second uses the block to return *a \<=\> b* .
|
200
|
-
#
|
200
|
+
#
|
201
201
|
# ```ruby
|
202
202
|
# a = %w(albatross dog horse)
|
203
203
|
# a.minmax #=> ["albatross", "horse"]
|
@@ -207,16 +207,16 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
207
207
|
| () { (Elem arg0, Elem arg1) -> Integer } -> [ Elem?, Elem? ]
|
208
208
|
|
209
209
|
def minmax_by: () -> [ Elem?, Elem? ]
|
210
|
-
| () { (Elem arg0) -> (Comparable | ::Array[untyped]) } ->
|
210
|
+
| () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> [ Elem?, Elem? ]
|
211
211
|
|
212
212
|
# Passes each element of the collection to the given block. The method
|
213
213
|
# returns `true` if the block never returns `true` for all elements. If
|
214
214
|
# the block is not given, `none?` will return `true` only if none of the
|
215
215
|
# collection members is true.
|
216
|
-
#
|
216
|
+
#
|
217
217
|
# If instead a pattern is supplied, the method returns whether `pattern
|
218
218
|
# === element` for none of the collection members.
|
219
|
-
#
|
219
|
+
#
|
220
220
|
# ```ruby
|
221
221
|
# %w{ant bear cat}.none? { |word| word.length == 5 } #=> true
|
222
222
|
# %w{ant bear cat}.none? { |word| word.length >= 4 } #=> false
|
@@ -228,16 +228,16 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
228
228
|
# [nil, false, true].none? #=> false
|
229
229
|
# ```
|
230
230
|
def none?: () -> bool
|
231
|
-
| () { (Elem
|
231
|
+
| () { (Elem) -> boolish } -> bool
|
232
232
|
|
233
233
|
# Passes each element of the collection to the given block. The method
|
234
234
|
# returns `true` if the block returns `true` exactly once. If the block is
|
235
235
|
# not given, `one?` will return `true` only if exactly one of the
|
236
236
|
# collection members is true.
|
237
|
-
#
|
237
|
+
#
|
238
238
|
# If instead a pattern is supplied, the method returns whether `pattern
|
239
239
|
# === element` for exactly one collection member.
|
240
|
-
#
|
240
|
+
#
|
241
241
|
# ```ruby
|
242
242
|
# %w{ant bear cat}.one? { |word| word.length == 4 } #=> true
|
243
243
|
# %w{ant bear cat}.one? { |word| word.length > 4 } #=> false
|
@@ -249,34 +249,34 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
249
249
|
# [].one? #=> false
|
250
250
|
# ```
|
251
251
|
def one?: () -> bool
|
252
|
-
| () { (Elem
|
252
|
+
| () { (Elem) -> boolish } -> bool
|
253
253
|
|
254
|
-
def partition: () { (Elem
|
255
|
-
| () -> ::Enumerator[Elem,
|
254
|
+
def partition: () { (Elem) -> boolish } -> [ ::Array[Elem], ::Array[Elem] ]
|
255
|
+
| () -> ::Enumerator[Elem, [ ::Array[Elem], ::Array[Elem] ]]
|
256
256
|
|
257
|
-
def reject: () { (Elem
|
258
|
-
| () -> ::Enumerator[Elem,
|
257
|
+
def reject: () { (Elem) -> boolish } -> ::Array[Elem]
|
258
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
259
259
|
|
260
|
-
def reverse_each: () { (Elem arg0) -> untyped } ->
|
261
|
-
| () -> ::Enumerator[Elem,
|
260
|
+
def reverse_each: () { (Elem arg0) -> untyped } -> void
|
261
|
+
| () -> ::Enumerator[Elem, void]
|
262
262
|
|
263
263
|
# Returns an array containing the items in *enum* sorted.
|
264
|
-
#
|
264
|
+
#
|
265
265
|
# Comparisons for the sort will be done using the items’ own `<=>`
|
266
266
|
# operator or using an optional code block.
|
267
|
-
#
|
267
|
+
#
|
268
268
|
# The block must implement a comparison between `a` and `b` and return an
|
269
269
|
# integer less than 0 when `b` follows `a`, `0` when `a` and `b` are
|
270
270
|
# equivalent, or an integer greater than 0 when `a` follows `b` .
|
271
|
-
#
|
271
|
+
#
|
272
272
|
# The result is not guaranteed to be stable. When the comparison of two
|
273
273
|
# elements returns `0`, the order of the elements is unpredictable.
|
274
|
-
#
|
274
|
+
#
|
275
275
|
# ```ruby
|
276
276
|
# %w(rhea kea flea).sort #=> ["flea", "kea", "rhea"]
|
277
277
|
# (1..10).sort { |a, b| b <=> a } #=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
|
278
278
|
# ```
|
279
|
-
#
|
279
|
+
#
|
280
280
|
# See also [\#sort\_by](Enumerable.downloaded.ruby_doc#method-i-sort_by).
|
281
281
|
# It implements a Schwartzian transform which is useful when key
|
282
282
|
# computation or comparison is expensive.
|
@@ -284,37 +284,44 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
284
284
|
| () { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
|
285
285
|
|
286
286
|
def sort_by: () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem]
|
287
|
-
| () -> ::Enumerator[Elem,
|
287
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
288
288
|
|
289
289
|
def take: (Integer n) -> ::Array[Elem]?
|
290
290
|
|
291
|
-
def take_while: () { (Elem
|
292
|
-
| () -> ::Enumerator[Elem,
|
291
|
+
def take_while: () { (Elem) -> boolish } -> ::Array[Elem]
|
292
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
293
293
|
|
294
294
|
# Implemented in C++
|
295
295
|
# Returns the result of interpreting *enum* as a list of `[key, value]`
|
296
296
|
# pairs.
|
297
|
-
#
|
297
|
+
#
|
298
298
|
# %i[hello world].each_with_index.to_h
|
299
299
|
# # => {:hello => 0, :world => 1}
|
300
|
-
#
|
300
|
+
#
|
301
301
|
# If a block is given, the results of the block on each element of the
|
302
302
|
# enum will be used as pairs.
|
303
|
-
#
|
303
|
+
#
|
304
304
|
# ```ruby
|
305
305
|
# (1..5).to_h {|x| [x, x ** 2]}
|
306
306
|
# #=> {1=>1, 2=>4, 3=>9, 4=>16, 5=>25}
|
307
307
|
# ```
|
308
308
|
def to_h: () -> ::Hash[untyped, untyped]
|
309
|
+
| [T, U] () { (Elem) -> [T, U] } -> ::Hash[T, U]
|
309
310
|
|
310
|
-
def each_slice: (Integer n) { (::Array[Elem]
|
311
|
-
| (Integer n) -> ::Enumerator[::Array[Elem],
|
311
|
+
def each_slice: (Integer n) { (::Array[Elem]) -> untyped } -> NilClass
|
312
|
+
| (Integer n) -> ::Enumerator[::Array[Elem], NilClass]
|
312
313
|
|
313
|
-
|
314
|
-
|
314
|
+
interface _NotFound[T]
|
315
|
+
def call: () -> T
|
316
|
+
end
|
315
317
|
|
316
|
-
def
|
317
|
-
|
318
|
+
def find: () { (Elem) -> boolish } -> Elem?
|
319
|
+
| () -> ::Enumerator[Elem, Elem?]
|
320
|
+
| [T] (_NotFound[T] ifnone) { (Elem) -> boolish } -> (Elem | T)
|
321
|
+
| [T] (_NotFound[T] ifnone) -> ::Enumerator[Elem, Elem | T]
|
322
|
+
|
323
|
+
def flat_map: [U] () { (Elem) -> (Array[U] | U) } -> Array[U]
|
324
|
+
| () -> ::Enumerator[Elem, Array[untyped]]
|
318
325
|
|
319
326
|
def map: [U] () { (Elem arg0) -> U } -> ::Array[U]
|
320
327
|
| () -> ::Enumerator[Elem, ::Array[untyped]]
|
@@ -324,11 +331,11 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
324
331
|
alias reduce inject
|
325
332
|
|
326
333
|
# Returns an array containing the items in *enum* .
|
327
|
-
#
|
334
|
+
#
|
328
335
|
# ```ruby
|
329
336
|
# (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7]
|
330
337
|
# { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]
|
331
|
-
#
|
338
|
+
#
|
332
339
|
# require 'prime'
|
333
340
|
# Prime.entries 10 #=> [2, 3, 5, 7]
|
334
341
|
# ```
|
@@ -342,10 +349,10 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
342
349
|
# [\#drop\_while](Enumerable.downloaded.ruby_doc#method-i-drop_while)
|
343
350
|
# enumerate values only on an as-needed basis. However, if a block is
|
344
351
|
# given to zip, values are enumerated immediately.
|
345
|
-
#
|
346
|
-
#
|
352
|
+
#
|
353
|
+
#
|
347
354
|
# The following program finds pythagorean triples:
|
348
|
-
#
|
355
|
+
#
|
349
356
|
# ```ruby
|
350
357
|
# def pythagorean_triples
|
351
358
|
# (1..Float::INFINITY).lazy.flat_map {|z|
|
@@ -364,7 +371,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
364
371
|
# # show pythagorean triples less than 100
|
365
372
|
# p pythagorean_triples.take_while { |*, z| z < 100 }.force
|
366
373
|
# ```
|
367
|
-
def lazy: () -> Enumerator::Lazy[Elem,
|
374
|
+
def lazy: () -> Enumerator::Lazy[Elem, void]
|
368
375
|
|
369
376
|
def uniq: () -> ::Array[Elem]
|
370
377
|
| () { (Elem item) -> untyped } -> ::Array[Elem]
|
@@ -375,30 +382,30 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
375
382
|
| [U] (?U arg0) { (Elem arg0) -> U } -> U
|
376
383
|
|
377
384
|
def filter_map: [U] () { (Elem elem) -> (nil | false | U) } -> ::Array[U]
|
378
|
-
| () -> ::Enumerator[Elem,
|
385
|
+
| () -> ::Enumerator[Elem, ::Array[untyped]]
|
379
386
|
|
380
|
-
def chain: (*self enumerables) -> ::Enumerator::Chain[Elem
|
387
|
+
def chain: (*self enumerables) -> ::Enumerator::Chain[Elem]
|
381
388
|
|
382
389
|
def tally: () -> ::Hash[Elem, Integer]
|
383
390
|
|
384
|
-
def each_entry: () -> ::Enumerator[Elem,
|
391
|
+
def each_entry: () -> ::Enumerator[Elem, self]
|
385
392
|
| () { (Elem arg0) -> untyped } -> self
|
386
393
|
|
387
394
|
# variadic type parameter is not supported yet
|
388
395
|
# https://github.com/ruby/rbs/issues/21
|
389
|
-
def zip: [Elem2
|
390
|
-
| [U, Elem2
|
396
|
+
def zip: [Elem2] (::Enumerable[Elem2] enum) -> ::Array[[Elem, Elem2 | nil]]
|
397
|
+
| [U, Elem2] (::Enumerable[Elem2]) { ([Elem, Elem2 | nil]) -> U } -> nil
|
391
398
|
|
392
|
-
def chunk: () -> ::Enumerator[Elem,
|
393
|
-
|
|
399
|
+
def chunk: [U] () { (Elem elt) -> U } -> ::Enumerator[[U, Array[Elem]], void]
|
400
|
+
| () -> ::Enumerator[Elem, Enumerator[untyped, untyped]]
|
394
401
|
|
395
|
-
def chunk_while: () { (Elem elt_before, Elem elt_after) ->
|
402
|
+
def chunk_while: () { (Elem elt_before, Elem elt_after) -> boolish } -> ::Enumerator[::Array[Elem], void]
|
396
403
|
|
397
|
-
def slice_when: () { (Elem elt_before, Elem elt_after) ->
|
404
|
+
def slice_when: () { (Elem elt_before, Elem elt_after) -> boolish } -> ::Enumerator[::Array[Elem], void]
|
398
405
|
|
399
406
|
def slice_after: (untyped pattern) -> ::Enumerator[::Array[Elem], void]
|
400
|
-
| () { (Elem elt) ->
|
407
|
+
| () { (Elem elt) -> boolish } -> ::Enumerator[::Array[Elem], void]
|
401
408
|
|
402
409
|
def slice_before: (untyped pattern) -> ::Enumerator[::Array[Elem], void]
|
403
|
-
| () { (Elem elt) ->
|
410
|
+
| () { (Elem elt) -> boolish } -> ::Enumerator[::Array[Elem], void]
|
404
411
|
end
|