rbs 0.12.2 → 0.16.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 +8 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +32 -0
- data/Gemfile +4 -0
- data/README.md +8 -2
- data/Rakefile +9 -2
- 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 +0 -0
- data/{stdlib/builtin → core}/encoding.rbs +33 -33
- data/{stdlib/builtin → core}/enumerable.rbs +58 -52
- data/{stdlib/builtin → core}/enumerator.rbs +35 -35
- 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 +7 -7
- data/{stdlib/builtin → core}/integer.rbs +0 -0
- data/{stdlib/builtin → core}/io.rbs +88 -88
- data/{stdlib/builtin → core}/kernel.rbs +71 -153
- 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 +3 -5
- 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 +1 -1
- 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 +117 -107
- data/lib/rbs/constant.rb +1 -1
- data/lib/rbs/constant_table.rb +9 -8
- data/lib/rbs/definition_builder.rb +6 -7
- data/lib/rbs/environment.rb +5 -1
- data/lib/rbs/environment_loader.rb +79 -105
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/parser.rb +3148 -0
- data/lib/rbs/parser.y +10 -3
- data/lib/rbs/prototype/rb.rb +38 -6
- 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 +2 -2
- data/lib/rbs/vendorer.rb +38 -16
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +25 -15
- data/sig/cli.rbs +58 -0
- data/sig/constant.rbs +21 -0
- data/sig/constant_table.rbs +30 -0
- data/sig/declarations.rbs +2 -2
- data/sig/definition.rbs +2 -2
- data/sig/definition_builder.rbs +6 -5
- data/sig/environment_loader.rbs +100 -0
- 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/version.rbs +3 -0
- data/sig/writer.rbs +40 -0
- 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} +1 -1
- 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} +41 -39
- data/stdlib/prime/{integer-extension.rbs → 0/integer-extension.rbs} +0 -0
- data/stdlib/prime/{prime.rbs → 0/prime.rbs} +0 -0
- 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} +0 -0
- data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +12 -12
- data/stdlib/uri/{file.rbs → 0/file.rbs} +0 -0
- data/stdlib/uri/{generic.rbs → 0/generic.rbs} +2 -2
- data/stdlib/uri/0/http.rbs +158 -0
- data/stdlib/uri/0/https.rbs +108 -0
- data/stdlib/uri/0/ldap.rbs +224 -0
- data/stdlib/uri/0/ldaps.rbs +108 -0
- data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
- data/steep/Gemfile.lock +13 -17
- metadata +105 -89
- data/stdlib/builtin/builtin.rbs +0 -42
File without changes
|
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
|
# ```
|
@@ -11,10 +11,10 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
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,18 +62,18 @@ 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
69
|
| (?Integer n) -> ::Enumerator[Elem, Return]
|
70
70
|
|
71
|
-
def detect: (?Proc ifnone) { (Elem
|
71
|
+
def detect: (?Proc ifnone) { (Elem) -> boolish } -> Elem?
|
72
72
|
| (?Proc ifnone) -> ::Enumerator[Elem, Return]
|
73
73
|
|
74
74
|
def drop: (Integer n) -> ::Array[Elem]
|
75
75
|
|
76
|
-
def drop_while: () { (Elem
|
76
|
+
def drop_while: () { (Elem) -> boolish } -> ::Array[Elem]
|
77
77
|
| () -> ::Enumerator[Elem, Return]
|
78
78
|
|
79
79
|
def each_cons: (Integer n) { (::Array[Elem] arg0) -> untyped } -> NilClass
|
@@ -86,30 +86,30 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
86
86
|
| [U] (U arg0) -> ::Enumerator[[ Elem, U ], Return]
|
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
|
99
|
+
def find_all: () { (Elem) -> boolish } -> ::Array[Elem]
|
100
100
|
| () -> ::Enumerator[Elem, Return]
|
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
|
106
|
+
| () { (Elem) -> boolish } -> Integer?
|
107
107
|
| () -> ::Enumerator[Elem, Return]
|
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"]
|
@@ -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"]
|
@@ -168,16 +168,16 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
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"]
|
@@ -197,7 +197,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
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"]
|
@@ -213,10 +213,10 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
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
|
254
|
+
def partition: () { (Elem) -> boolish } -> [ ::Array[Elem], ::Array[Elem] ]
|
255
255
|
| () -> ::Enumerator[Elem, Return]
|
256
256
|
|
257
|
-
def reject: () { (Elem
|
257
|
+
def reject: () { (Elem) -> boolish } -> ::Array[Elem]
|
258
258
|
| () -> ::Enumerator[Elem, Return]
|
259
259
|
|
260
260
|
def reverse_each: () { (Elem arg0) -> untyped } -> ::Enumerator[Elem, Return]
|
261
261
|
| () -> ::Enumerator[Elem, Return]
|
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.
|
@@ -288,30 +288,36 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
288
288
|
|
289
289
|
def take: (Integer n) -> ::Array[Elem]?
|
290
290
|
|
291
|
-
def take_while: () { (Elem
|
291
|
+
def take_while: () { (Elem) -> boolish } -> ::Array[Elem]
|
292
292
|
| () -> ::Enumerator[Elem, Return]
|
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
309
|
|
310
|
-
def each_slice: (Integer n) { (::Array[Elem]
|
310
|
+
def each_slice: (Integer n) { (::Array[Elem]) -> untyped } -> NilClass
|
311
311
|
| (Integer n) -> ::Enumerator[::Array[Elem], Return]
|
312
312
|
|
313
|
-
|
314
|
-
|
313
|
+
interface _NotFound[T]
|
314
|
+
def call: () -> T
|
315
|
+
end
|
316
|
+
|
317
|
+
def find: () { (Elem) -> boolish } -> Elem?
|
318
|
+
| () -> ::Enumerator[Elem, Elem?]
|
319
|
+
| [T] (_NotFound[T] ifnone) { (Elem) -> boolish } -> (Elem | T)
|
320
|
+
| [T] (_NotFound[T] ifnone) -> ::Enumerator[Elem, Elem | T]
|
315
321
|
|
316
322
|
def flat_map: [U] () { (Elem arg0) -> U } -> U
|
317
323
|
| () -> ::Enumerator[Elem, Return]
|
@@ -324,11 +330,11 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
324
330
|
alias reduce inject
|
325
331
|
|
326
332
|
# Returns an array containing the items in *enum* .
|
327
|
-
#
|
333
|
+
#
|
328
334
|
# ```ruby
|
329
335
|
# (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7]
|
330
336
|
# { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]
|
331
|
-
#
|
337
|
+
#
|
332
338
|
# require 'prime'
|
333
339
|
# Prime.entries 10 #=> [2, 3, 5, 7]
|
334
340
|
# ```
|
@@ -342,10 +348,10 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
342
348
|
# [\#drop\_while](Enumerable.downloaded.ruby_doc#method-i-drop_while)
|
343
349
|
# enumerate values only on an as-needed basis. However, if a block is
|
344
350
|
# given to zip, values are enumerated immediately.
|
345
|
-
#
|
346
|
-
#
|
351
|
+
#
|
352
|
+
#
|
347
353
|
# The following program finds pythagorean triples:
|
348
|
-
#
|
354
|
+
#
|
349
355
|
# ```ruby
|
350
356
|
# def pythagorean_triples
|
351
357
|
# (1..Float::INFINITY).lazy.flat_map {|z|
|
@@ -392,13 +398,13 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
|
|
392
398
|
def chunk: () -> ::Enumerator[Elem, Return]
|
393
399
|
| [U] () { (Elem elt) -> U } -> ::Enumerator[[U, Array[Elem]], void]
|
394
400
|
|
395
|
-
def chunk_while: () { (Elem elt_before, Elem elt_after) ->
|
401
|
+
def chunk_while: () { (Elem elt_before, Elem elt_after) -> boolish } -> ::Enumerator[::Array[Elem], void]
|
396
402
|
|
397
|
-
def slice_when: () { (Elem elt_before, Elem elt_after) ->
|
403
|
+
def slice_when: () { (Elem elt_before, Elem elt_after) -> boolish } -> ::Enumerator[::Array[Elem], void]
|
398
404
|
|
399
405
|
def slice_after: (untyped pattern) -> ::Enumerator[::Array[Elem], void]
|
400
|
-
| () { (Elem elt) ->
|
406
|
+
| () { (Elem elt) -> boolish } -> ::Enumerator[::Array[Elem], void]
|
401
407
|
|
402
408
|
def slice_before: (untyped pattern) -> ::Enumerator[::Array[Elem], void]
|
403
|
-
| () { (Elem elt) ->
|
409
|
+
| () { (Elem elt) -> boolish } -> ::Enumerator[::Array[Elem], void]
|
404
410
|
end
|