steep 0.13.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +28 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep.rb +33 -1
  9. data/lib/steep/annotation_parser.rb +4 -4
  10. data/lib/steep/ast/buffer.rb +11 -7
  11. data/lib/steep/ast/builtin.rb +8 -0
  12. data/lib/steep/ast/types/factory.rb +124 -89
  13. data/lib/steep/cli.rb +16 -1
  14. data/lib/steep/drivers/annotations.rb +1 -1
  15. data/lib/steep/drivers/check.rb +20 -4
  16. data/lib/steep/drivers/init.rb +5 -5
  17. data/lib/steep/drivers/langserver.rb +13 -287
  18. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  19. data/lib/steep/drivers/vendor.rb +2 -2
  20. data/lib/steep/drivers/watch.rb +97 -85
  21. data/lib/steep/drivers/worker.rb +51 -0
  22. data/lib/steep/project.rb +9 -5
  23. data/lib/steep/project/completion_provider.rb +298 -0
  24. data/lib/steep/project/dsl.rb +14 -0
  25. data/lib/steep/project/file.rb +54 -47
  26. data/lib/steep/project/hover_content.rb +17 -8
  27. data/lib/steep/project/options.rb +25 -3
  28. data/lib/steep/project/target.rb +40 -24
  29. data/lib/steep/server/base_worker.rb +56 -0
  30. data/lib/steep/server/code_worker.rb +151 -0
  31. data/lib/steep/server/interaction_worker.rb +281 -0
  32. data/lib/steep/server/master.rb +196 -0
  33. data/lib/steep/server/signature_worker.rb +148 -0
  34. data/lib/steep/server/utils.rb +36 -0
  35. data/lib/steep/server/worker_process.rb +62 -0
  36. data/lib/steep/signature/errors.rb +1 -1
  37. data/lib/steep/signature/validator.rb +13 -13
  38. data/lib/steep/source.rb +1 -1
  39. data/lib/steep/type_construction.rb +1004 -727
  40. data/lib/steep/type_inference/constant_env.rb +3 -11
  41. data/lib/steep/type_inference/context.rb +8 -3
  42. data/lib/steep/type_inference/context_array.rb +111 -0
  43. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  44. data/lib/steep/type_inference/logic.rb +130 -0
  45. data/lib/steep/type_inference/type_env.rb +5 -69
  46. data/lib/steep/typing.rb +91 -23
  47. data/lib/steep/version.rb +1 -1
  48. data/smoke/alias/Steepfile +1 -0
  49. data/smoke/alias/a.rb +1 -1
  50. data/smoke/and/Steepfile +1 -0
  51. data/smoke/array/Steepfile +1 -0
  52. data/smoke/array/b.rb +0 -2
  53. data/smoke/block/Steepfile +1 -0
  54. data/smoke/case/Steepfile +1 -0
  55. data/smoke/class/Steepfile +1 -0
  56. data/smoke/const/Steepfile +1 -0
  57. data/smoke/dstr/Steepfile +1 -0
  58. data/smoke/ensure/Steepfile +1 -0
  59. data/smoke/enumerator/Steepfile +1 -0
  60. data/smoke/extension/Steepfile +1 -0
  61. data/smoke/extension/c.rb +1 -0
  62. data/smoke/hash/Steepfile +1 -0
  63. data/smoke/hello/Steepfile +1 -0
  64. data/smoke/if/Steepfile +1 -0
  65. data/smoke/if/a.rb +1 -1
  66. data/smoke/implements/Steepfile +1 -0
  67. data/smoke/initialize/Steepfile +1 -0
  68. data/smoke/integer/Steepfile +1 -0
  69. data/smoke/interface/Steepfile +1 -0
  70. data/smoke/kwbegin/Steepfile +1 -0
  71. data/smoke/lambda/Steepfile +1 -0
  72. data/smoke/literal/Steepfile +1 -0
  73. data/smoke/map/Steepfile +1 -0
  74. data/smoke/method/Steepfile +1 -0
  75. data/smoke/module/Steepfile +1 -0
  76. data/smoke/regexp/Steepfile +1 -0
  77. data/smoke/regexp/b.rb +4 -4
  78. data/smoke/regression/Steepfile +1 -0
  79. data/smoke/rescue/Steepfile +1 -0
  80. data/smoke/rescue/a.rb +1 -1
  81. data/smoke/self/Steepfile +1 -0
  82. data/smoke/skip/Steepfile +1 -0
  83. data/smoke/stdout/Steepfile +1 -0
  84. data/smoke/super/Steepfile +1 -0
  85. data/smoke/type_case/Steepfile +1 -0
  86. data/smoke/yield/Steepfile +1 -0
  87. data/steep.gemspec +8 -8
  88. metadata +38 -138
  89. data/exe/rbs +0 -3
  90. data/exe/ruby-signature +0 -3
  91. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  92. data/vendor/ruby-signature/.gitignore +0 -12
  93. data/vendor/ruby-signature/.rubocop.yml +0 -15
  94. data/vendor/ruby-signature/BSDL +0 -22
  95. data/vendor/ruby-signature/COPYING +0 -56
  96. data/vendor/ruby-signature/Gemfile +0 -6
  97. data/vendor/ruby-signature/README.md +0 -93
  98. data/vendor/ruby-signature/Rakefile +0 -66
  99. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
  100. data/vendor/ruby-signature/bin/console +0 -14
  101. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  102. data/vendor/ruby-signature/bin/setup +0 -10
  103. data/vendor/ruby-signature/bin/sort +0 -88
  104. data/vendor/ruby-signature/bin/test_runner.rb +0 -17
  105. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  106. data/vendor/ruby-signature/docs/sigs.md +0 -148
  107. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  108. data/vendor/ruby-signature/docs/syntax.md +0 -528
  109. data/vendor/ruby-signature/exe/rbs +0 -3
  110. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  111. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
  112. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  113. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  114. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  115. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  116. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  117. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  118. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
  119. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  120. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  121. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  122. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  123. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  124. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  125. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  126. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  127. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  128. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  129. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  130. data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
  131. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
  132. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  133. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  134. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  135. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  136. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  137. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  138. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
  139. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
  140. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  141. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  142. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  143. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  144. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  145. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  146. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  147. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
  148. data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
  149. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
  150. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
  151. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  152. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  153. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  154. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
  155. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  156. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  157. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  158. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  159. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  160. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  161. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
  162. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
  163. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  164. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  165. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  166. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  167. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
  168. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  169. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  170. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  171. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
  172. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  173. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  174. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
  175. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  176. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
  177. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  178. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
  179. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
  180. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
  181. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
  182. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
  183. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
  184. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  185. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  186. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  187. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
  188. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
  189. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
  190. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  191. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  192. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
  193. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
  194. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  195. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  196. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
  197. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
  198. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  199. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
  200. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
  201. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  202. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
  203. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
  204. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  205. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
  206. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  207. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
  208. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
  209. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
  210. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  211. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  212. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  213. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
  214. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,404 +0,0 @@
1
- # The `Enumerable` mixin provides collection classes with several
2
- # traversal and searching methods, and with the ability to sort. The class
3
- # must provide a method `each`, which yields successive members of the
4
- # collection. If `Enumerable#max`, `#min`, or `#sort` is used, the
5
- # objects in the collection must also implement a meaningful `<=>`
6
- # operator, as these methods rely on an ordering between members of the
7
- # collection.
8
- module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
9
- # Passes each element of the collection to the given block. The method
10
- # returns `true` if the block never returns `false` or `nil` . If the
11
- # block is not given, Ruby adds an implicit block of `{ |obj| obj }` which
12
- # will cause [all?](Enumerable.downloaded.ruby_doc#method-i-all-3F) to
13
- # return `true` when none of the collection members are `false` or `nil` .
14
- #
15
- # If instead a pattern is supplied, the method returns whether `pattern
16
- # === element` for every collection member.
17
- #
18
- # %w[ant bear cat].all? { |word| word.length >= 3 } #=> true
19
- # %w[ant bear cat].all? { |word| word.length >= 4 } #=> false
20
- # %w[ant bear cat].all?(/t/) #=> false
21
- # [1, 2i, 3.14].all?(Numeric) #=> true
22
- # [nil, true, 99].all? #=> false
23
- # [].all? #=> true
24
- def all?: () -> bool
25
- | () { (Elem arg0) -> untyped } -> bool
26
-
27
- # Passes each element of the collection to the given block. The method
28
- # returns `true` if the block ever returns a value other than `false` or
29
- # `nil` . If the block is not given, Ruby adds an implicit block of `{
30
- # |obj| obj }` that will cause
31
- # [any?](Enumerable.downloaded.ruby_doc#method-i-any-3F) to return `true`
32
- # if at least one of the collection members is not `false` or `nil` .
33
- #
34
- # If instead a pattern is supplied, the method returns whether `pattern
35
- # === element` for any collection member.
36
- #
37
- # ```ruby
38
- # %w[ant bear cat].any? { |word| word.length >= 3 } #=> true
39
- # %w[ant bear cat].any? { |word| word.length >= 4 } #=> true
40
- # %w[ant bear cat].any?(/d/) #=> false
41
- # [nil, true, 99].any?(Integer) #=> true
42
- # [nil, true, 99].any? #=> true
43
- # [].any? #=> false
44
- # ```
45
- def `any?`: () -> bool
46
- | () { (Elem arg0) -> untyped } -> bool
47
-
48
- def collect: [U] () { (Elem arg0) -> U } -> ::Array[U]
49
- | () -> ::Enumerator[Elem, Return]
50
-
51
- def collect_concat: [U] () { (Elem arg0) -> ::Enumerator[U, untyped] } -> ::Array[U]
52
-
53
- # Returns the number of items in `enum` through enumeration. If an
54
- # argument is given, the number of items in `enum` that are equal to
55
- # `item` are counted. If a block is given, it counts the number of
56
- # elements yielding a true value.
57
- #
58
- # ```ruby
59
- # ary = [1, 2, 4, 2]
60
- # ary.count #=> 4
61
- # ary.count(2) #=> 2
62
- # ary.count{ |x| x%2==0 } #=> 3
63
- # ```
64
- def count: () -> Integer
65
- | (?untyped arg0) -> Integer
66
- | () { (Elem arg0) -> untyped } -> Integer
67
-
68
- def cycle: (?Integer n) { (Elem arg0) -> untyped } -> NilClass
69
- | (?Integer n) -> ::Enumerator[Elem, Return]
70
-
71
- def detect: (?Proc ifnone) { (Elem arg0) -> untyped } -> Elem?
72
- | (?Proc ifnone) -> ::Enumerator[Elem, Return]
73
-
74
- def drop: (Integer n) -> ::Array[Elem]
75
-
76
- def drop_while: () { (Elem arg0) -> untyped } -> ::Array[Elem]
77
- | () -> ::Enumerator[Elem, Return]
78
-
79
- def each_cons: (Integer n) { (::Array[Elem] arg0) -> untyped } -> NilClass
80
- | (Integer n) -> ::Enumerator[::Array[Elem], Return]
81
-
82
- def each_with_index: () { (Elem arg0, Integer arg1) -> untyped } -> ::Enumerable[Elem, Return]
83
- | () -> ::Enumerator[[ Elem, Integer ], Return]
84
-
85
- def each_with_object: [U] (U arg0) { (Elem arg0, untyped arg1) -> untyped } -> U
86
- | [U] (U arg0) -> ::Enumerator[[ Elem, U ], Return]
87
-
88
- # Returns an array containing the items in *enum* .
89
- #
90
- # ```ruby
91
- # (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7]
92
- # { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]
93
- #
94
- # require 'prime'
95
- # Prime.entries 10 #=> [2, 3, 5, 7]
96
- # ```
97
- def entries: () -> ::Array[Elem]
98
-
99
- def find_all: () { (Elem arg0) -> untyped } -> ::Array[Elem]
100
- | () -> ::Enumerator[Elem, Return]
101
-
102
- alias select find_all
103
- alias filter find_all
104
-
105
- def find_index: (?untyped value) -> Integer?
106
- | () { (Elem arg0) -> untyped } -> Integer?
107
- | () -> ::Enumerator[Elem, Return]
108
-
109
- # Returns the first element, or the first `n` elements, of the enumerable.
110
- # If the enumerable is empty, the first form returns `nil`, and the
111
- # second form returns an empty array.
112
- #
113
- # ```ruby
114
- # %w[foo bar baz].first #=> "foo"
115
- # %w[foo bar baz].first(2) #=> ["foo", "bar"]
116
- # %w[foo bar baz].first(10) #=> ["foo", "bar", "baz"]
117
- # [].first #=> nil
118
- # [].first(10) #=> []
119
- # ```
120
- def first: () -> Elem?
121
- | (?Integer n) -> ::Array[Elem]?
122
-
123
- def grep: (untyped arg0) -> ::Array[Elem]
124
- | [U] (untyped arg0) { (Elem arg0) -> U } -> ::Array[U]
125
-
126
- def grep_v: (untyped arg0) -> ::Array[Integer]
127
- | [U] (untyped arg0) { (Elem arg0) -> U } -> ::Array[U]
128
-
129
- def group_by: [U] () { (Elem arg0) -> U } -> ::Hash[U, ::Array[Elem]]
130
- | () -> ::Enumerator[Elem, Return]
131
-
132
- def `include?`: (untyped arg0) -> bool
133
-
134
- def inject: (untyped init, Symbol method) -> untyped
135
- | (Symbol method) -> untyped
136
- | [A] (A initial) { (Elem, A) -> A } -> Elem
137
- | () { (Elem, Elem) -> Elem } -> Elem
138
-
139
- # Returns the object in *enum* with the maximum value. The first form
140
- # assumes all objects implement `Comparable` ; the second uses the block
141
- # to return *a \<=\> b* .
142
- #
143
- # ```ruby
144
- # a = %w(albatross dog horse)
145
- # a.max #=> "horse"
146
- # a.max { |a, b| a.length <=> b.length } #=> "albatross"
147
- # ```
148
- #
149
- # If the `n` argument is given, maximum `n` elements are returned as an
150
- # array, sorted in descending order.
151
- #
152
- # ```ruby
153
- # a = %w[albatross dog horse]
154
- # a.max(2) #=> ["horse", "dog"]
155
- # a.max(2) {|a, b| a.length <=> b.length } #=> ["albatross", "horse"]
156
- # [5, 1, 3, 4, 2].max(3) #=> [5, 4, 3]
157
- # ```
158
- def max: () -> Elem?
159
- | () { (Elem arg0, Elem arg1) -> Integer } -> Elem?
160
- | (?Integer arg0) -> ::Array[Elem]
161
- | (?Integer arg0) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
162
-
163
- def max_by: () -> ::Enumerator[Elem, Return]
164
- | () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> Elem?
165
- | (?Integer arg0) -> ::Enumerator[Elem, Return]
166
- | (?Integer arg0) { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem]
167
-
168
- # Returns the object in *enum* with the minimum value. The first form
169
- # assumes all objects implement `Comparable` ; the second uses the block
170
- # to return *a \<=\> b* .
171
- #
172
- # ```ruby
173
- # a = %w(albatross dog horse)
174
- # a.min #=> "albatross"
175
- # a.min { |a, b| a.length <=> b.length } #=> "dog"
176
- # ```
177
- #
178
- # If the `n` argument is given, minimum `n` elements are returned as a
179
- # sorted array.
180
- #
181
- # ```ruby
182
- # a = %w[albatross dog horse]
183
- # a.min(2) #=> ["albatross", "dog"]
184
- # a.min(2) {|a, b| a.length <=> b.length } #=> ["dog", "horse"]
185
- # [5, 1, 3, 4, 2].min(3) #=> [1, 2, 3]
186
- # ```
187
- def min: () -> Elem?
188
- | () { (Elem arg0, Elem arg1) -> Integer } -> Elem?
189
- | (?Integer arg0) -> ::Array[Elem]
190
- | (?Integer arg0) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
191
-
192
- def min_by: () -> ::Enumerator[Elem, Return]
193
- | () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> Elem?
194
- | (?Integer arg0) -> ::Enumerator[Elem, Return]
195
- | (?Integer arg0) { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem]
196
-
197
- # Returns a two element array which contains the minimum and the maximum
198
- # value in the enumerable. The first form assumes all objects implement
199
- # `Comparable` ; the second uses the block to return *a \<=\> b* .
200
- #
201
- # ```ruby
202
- # a = %w(albatross dog horse)
203
- # a.minmax #=> ["albatross", "horse"]
204
- # a.minmax { |a, b| a.length <=> b.length } #=> ["dog", "albatross"]
205
- # ```
206
- def minmax: () -> [ Elem?, Elem? ]
207
- | () { (Elem arg0, Elem arg1) -> Integer } -> [ Elem?, Elem? ]
208
-
209
- def minmax_by: () -> [ Elem?, Elem? ]
210
- | () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Enumerator[Elem, Return]
211
-
212
- # Passes each element of the collection to the given block. The method
213
- # returns `true` if the block never returns `true` for all elements. If
214
- # the block is not given, `none?` will return `true` only if none of the
215
- # collection members is true.
216
- #
217
- # If instead a pattern is supplied, the method returns whether `pattern
218
- # === element` for none of the collection members.
219
- #
220
- # ```ruby
221
- # %w{ant bear cat}.none? { |word| word.length == 5 } #=> true
222
- # %w{ant bear cat}.none? { |word| word.length >= 4 } #=> false
223
- # %w{ant bear cat}.none?(/d/) #=> true
224
- # [1, 3.14, 42].none?(Float) #=> false
225
- # [].none? #=> true
226
- # [nil].none? #=> true
227
- # [nil, false].none? #=> true
228
- # [nil, false, true].none? #=> false
229
- # ```
230
- def none?: () -> bool
231
- | () { (Elem arg0) -> untyped } -> bool
232
-
233
- # Passes each element of the collection to the given block. The method
234
- # returns `true` if the block returns `true` exactly once. If the block is
235
- # not given, `one?` will return `true` only if exactly one of the
236
- # collection members is true.
237
- #
238
- # If instead a pattern is supplied, the method returns whether `pattern
239
- # === element` for exactly one collection member.
240
- #
241
- # ```ruby
242
- # %w{ant bear cat}.one? { |word| word.length == 4 } #=> true
243
- # %w{ant bear cat}.one? { |word| word.length > 4 } #=> false
244
- # %w{ant bear cat}.one? { |word| word.length < 4 } #=> false
245
- # %w{ant bear cat}.one?(/t/) #=> false
246
- # [ nil, true, 99 ].one? #=> false
247
- # [ nil, true, false ].one? #=> true
248
- # [ nil, true, 99 ].one?(Integer) #=> true
249
- # [].one? #=> false
250
- # ```
251
- def one?: () -> bool
252
- | () { (Elem arg0) -> untyped } -> bool
253
-
254
- def partition: () { (Elem arg0) -> untyped } -> [ ::Array[Elem], ::Array[Elem] ]
255
- | () -> ::Enumerator[Elem, Return]
256
-
257
- def reject: () { (Elem arg0) -> untyped } -> ::Array[Elem]
258
- | () -> ::Enumerator[Elem, Return]
259
-
260
- def reverse_each: () { (Elem arg0) -> untyped } -> ::Enumerator[Elem, Return]
261
- | () -> ::Enumerator[Elem, Return]
262
-
263
- # Returns an array containing the items in *enum* sorted.
264
- #
265
- # Comparisons for the sort will be done using the items’ own `<=>`
266
- # operator or using an optional code block.
267
- #
268
- # The block must implement a comparison between `a` and `b` and return an
269
- # integer less than 0 when `b` follows `a`, `0` when `a` and `b` are
270
- # equivalent, or an integer greater than 0 when `a` follows `b` .
271
- #
272
- # The result is not guaranteed to be stable. When the comparison of two
273
- # elements returns `0`, the order of the elements is unpredictable.
274
- #
275
- # ```ruby
276
- # %w(rhea kea flea).sort #=> ["flea", "kea", "rhea"]
277
- # (1..10).sort { |a, b| b <=> a } #=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
278
- # ```
279
- #
280
- # See also [\#sort\_by](Enumerable.downloaded.ruby_doc#method-i-sort_by).
281
- # It implements a Schwartzian transform which is useful when key
282
- # computation or comparison is expensive.
283
- def sort: () -> ::Array[Elem]
284
- | () { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
285
-
286
- def sort_by: () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem]
287
- | () -> ::Enumerator[Elem, Return]
288
-
289
- def take: (Integer n) -> ::Array[Elem]?
290
-
291
- def take_while: () { (Elem arg0) -> untyped } -> ::Array[Elem]
292
- | () -> ::Enumerator[Elem, Return]
293
-
294
- # Implemented in C++
295
- # Returns the result of interpreting *enum* as a list of `[key, value]`
296
- # pairs.
297
- #
298
- # %i[hello world].each_with_index.to_h
299
- # # => {:hello => 0, :world => 1}
300
- #
301
- # If a block is given, the results of the block on each element of the
302
- # enum will be used as pairs.
303
- #
304
- # ```ruby
305
- # (1..5).to_h {|x| [x, x ** 2]}
306
- # #=> {1=>1, 2=>4, 3=>9, 4=>16, 5=>25}
307
- # ```
308
- def to_h: () -> ::Hash[untyped, untyped]
309
-
310
- def each_slice: (Integer n) { (::Array[Elem] arg0) -> untyped } -> NilClass
311
- | (Integer n) -> ::Enumerator[::Array[Elem], Return]
312
-
313
- def find: (?Proc ifnone) { (Elem arg0) -> untyped } -> Elem?
314
- | (?Proc ifnone) -> ::Enumerator[Elem, Return]
315
-
316
- def flat_map: [U] () { (Elem arg0) -> U } -> U
317
- | () -> ::Enumerator[Elem, Return]
318
-
319
- def map: [U] () { (Elem arg0) -> U } -> ::Array[U]
320
- | () -> ::Enumerator[Elem, Return]
321
-
322
- def member?: (untyped arg0) -> bool
323
-
324
- alias reduce inject
325
-
326
- # Returns an array containing the items in *enum* .
327
- #
328
- # ```ruby
329
- # (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7]
330
- # { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]
331
- #
332
- # require 'prime'
333
- # Prime.entries 10 #=> [2, 3, 5, 7]
334
- # ```
335
- def to_a: () -> ::Array[Elem]
336
-
337
- # Returns a lazy enumerator, whose methods map/collect,
338
- # flat\_map/collect\_concat, select/find\_all, reject, grep,
339
- # [\#grep\_v](Enumerable.downloaded.ruby_doc#method-i-grep_v), zip, take,
340
- # [\#take\_while](Enumerable.downloaded.ruby_doc#method-i-take_while),
341
- # drop, and
342
- # [\#drop\_while](Enumerable.downloaded.ruby_doc#method-i-drop_while)
343
- # enumerate values only on an as-needed basis. However, if a block is
344
- # given to zip, values are enumerated immediately.
345
- #
346
- #
347
- # The following program finds pythagorean triples:
348
- #
349
- # ```ruby
350
- # def pythagorean_triples
351
- # (1..Float::INFINITY).lazy.flat_map {|z|
352
- # (1..z).flat_map {|x|
353
- # (x..z).select {|y|
354
- # x**2 + y**2 == z**2
355
- # }.map {|y|
356
- # [x, y, z]
357
- # }
358
- # }
359
- # }
360
- # end
361
- # # show first ten pythagorean triples
362
- # p pythagorean_triples.take(10).force # take is lazy, so force is needed
363
- # p pythagorean_triples.first(10) # first is eager
364
- # # show pythagorean triples less than 100
365
- # p pythagorean_triples.take_while { |*, z| z < 100 }.force
366
- # ```
367
- def lazy: () -> Enumerator::Lazy[Elem, Return]
368
-
369
- def uniq: () -> ::Array[Elem]
370
- | () { (Elem item) -> untyped } -> ::Array[Elem]
371
-
372
- def sum: () -> (Elem | Integer)
373
- | [T] () { (Elem arg0) -> T } -> (Integer | T)
374
- | [T] (?T arg0) -> (Elem | T)
375
- | [U] (?U arg0) { (Elem arg0) -> U } -> U
376
-
377
- def filter_map: [U] () { (Elem arg0) -> U? } -> ::Array[U]
378
- | () -> ::Enumerator[Elem, Return]
379
-
380
- def chain: (*self enumerables) -> ::Enumerator::Chain[Elem, ::Array[self]]
381
-
382
- def tally: () -> ::Hash[Elem, Integer]
383
-
384
- def each_entry: () -> ::Enumerator[Elem, Return]
385
- | () { (Elem arg0) -> untyped } -> self
386
-
387
- # variadic type parameter is not supported yet
388
- # https://github.com/ruby/ruby-signature/issues/21
389
- def zip: [Elem2, Return2] (::Enumerable[Elem2, Return2] enum) -> ::Array[[Elem, Elem2 | nil]]
390
- | [U, Elem2, Return2] (::Enumerable[Elem2, Return2]) { ([Elem, Elem2 | nil]) -> U } -> nil
391
-
392
- def chunk: () -> ::Enumerator[Elem, Return]
393
- | [U] () { (Elem elt) -> U } -> ::Enumerator[[U, Array[Elem]], void]
394
-
395
- def chunk_while: () { (Elem elt_before, Elem elt_after) -> bool } -> ::Enumerator[::Array[Elem], void]
396
-
397
- def slice_when: () { (Elem elt_before, Elem elt_after) -> bool } -> ::Enumerator[::Array[Elem], void]
398
-
399
- def slice_after: (untyped pattern) -> ::Enumerator[::Array[Elem], void]
400
- | () { (Elem elt) -> bool } -> ::Enumerator[::Array[Elem], void]
401
-
402
- def slice_before: (untyped pattern) -> ::Enumerator[::Array[Elem], void]
403
- | () { (Elem elt) -> bool } -> ::Enumerator[::Array[Elem], void]
404
- end
@@ -1,260 +0,0 @@
1
- # A class which allows both internal and external iteration.
2
- #
3
- # An [Enumerator](Enumerator) can be created by the
4
- # following methods.
5
- #
6
- # - Kernel\#to\_enum
7
- #
8
- # - Kernel\#enum\_for
9
- #
10
- # - [::new](Enumerator#method-c-new)
11
- #
12
- # Most methods have two forms: a block form where the contents are
13
- # evaluated for each item in the enumeration, and a non-block form which
14
- # returns a new [Enumerator](Enumerator) wrapping the
15
- # iteration.
16
- #
17
- # ```ruby
18
- # enumerator = %w(one two three).each
19
- # puts enumerator.class # => Enumerator
20
- #
21
- # enumerator.each_with_object("foo") do |item, obj|
22
- # puts "#{obj}: #{item}"
23
- # end
24
- #
25
- # # foo: one
26
- # # foo: two
27
- # # foo: three
28
- #
29
- # enum_with_obj = enumerator.each_with_object("foo")
30
- # puts enum_with_obj.class # => Enumerator
31
- #
32
- # enum_with_obj.each do |item, obj|
33
- # puts "#{obj}: #{item}"
34
- # end
35
- #
36
- # # foo: one
37
- # # foo: two
38
- # # foo: three
39
- # ```
40
- #
41
- # This allows you to chain Enumerators together. For example, you can map
42
- # a list's elements to strings containing the index and the element as a
43
- # string via:
44
- #
45
- # ```ruby
46
- # puts %w[foo bar baz].map.with_index { |w, i| "#{i}:#{w}" }
47
- # # => ["0:foo", "1:bar", "2:baz"]
48
- # ```
49
- #
50
- # An [Enumerator](Enumerator) can also be used as an
51
- # external iterator. For example,
52
- # [\#next](Enumerator#method-i-next) returns the next
53
- # value of the iterator or raises
54
- # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html) if
55
- # the [Enumerator](Enumerator) is at the end.
56
- #
57
- # ```ruby
58
- # e = [1,2,3].each # returns an enumerator object.
59
- # puts e.next # => 1
60
- # puts e.next # => 2
61
- # puts e.next # => 3
62
- # puts e.next # raises StopIteration
63
- # ```
64
- #
65
- # You can use this to implement an internal iterator as follows:
66
- #
67
- # ```ruby
68
- # def ext_each(e)
69
- # while true
70
- # begin
71
- # vs = e.next_values
72
- # rescue StopIteration
73
- # return $!.result
74
- # end
75
- # y = yield(*vs)
76
- # e.feed y
77
- # end
78
- # end
79
- #
80
- # o = Object.new
81
- #
82
- # def o.each
83
- # puts yield
84
- # puts yield(1)
85
- # puts yield(1, 2)
86
- # 3
87
- # end
88
- #
89
- # # use o.each as an internal iterator directly.
90
- # puts o.each {|*x| puts x; [:b, *x] }
91
- # # => [], [:b], [1], [:b, 1], [1, 2], [:b, 1, 2], 3
92
- #
93
- # # convert o.each to an external iterator for
94
- # # implementing an internal iterator.
95
- # puts ext_each(o.to_enum) {|*x| puts x; [:b, *x] }
96
- # # => [], [:b], [1], [:b, 1], [1, 2], [:b, 1, 2], 3
97
- # ```
98
- class Enumerator[unchecked out Elem, out Return] < Object
99
- include Enumerable[Elem, Return]
100
-
101
- def each: () { (Elem arg0) -> untyped } -> Return
102
- | () -> self
103
-
104
- def feed: (Elem arg0) -> NilClass
105
-
106
- def initialize: (?Integer arg0) { (Enumerator::Yielder arg0) -> void } -> void
107
-
108
- # Creates a printable version of *e* .
109
- def inspect: () -> String
110
-
111
- # Returns the next object in the enumerator, and move the internal
112
- # position forward. When the position reached at the end,
113
- # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html) is
114
- # raised.
115
- #
116
- #
117
- # ```ruby
118
- # a = [1,2,3]
119
- # e = a.to_enum
120
- # p e.next #=> 1
121
- # p e.next #=> 2
122
- # p e.next #=> 3
123
- # p e.next #raises StopIteration
124
- # ```
125
- #
126
- # Note that enumeration sequence by `next` does not affect other
127
- # non-external enumeration methods, unless the underlying iteration
128
- # methods itself has side-effect, e.g.
129
- # [IO\#each\_line](https://ruby-doc.org/core-2.6.3/IO.html#method-i-each_line)
130
- # .
131
- def next: () -> Elem
132
-
133
- # Returns the next object as an array in the enumerator, and move the
134
- # internal position forward. When the position reached at the end,
135
- # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html) is
136
- # raised.
137
- #
138
- # This method can be used to distinguish `yield` and `yield nil` .
139
- #
140
- #
141
- # ```ruby
142
- # o = Object.new
143
- # def o.each
144
- # yield
145
- # yield 1
146
- # yield 1, 2
147
- # yield nil
148
- # yield [1, 2]
149
- # end
150
- # e = o.to_enum
151
- # p e.next_values
152
- # p e.next_values
153
- # p e.next_values
154
- # p e.next_values
155
- # p e.next_values
156
- # e = o.to_enum
157
- # p e.next
158
- # p e.next
159
- # p e.next
160
- # p e.next
161
- # p e.next
162
- #
163
- # ## yield args next_values next
164
- # # yield [] nil
165
- # # yield 1 [1] 1
166
- # # yield 1, 2 [1, 2] [1, 2]
167
- # # yield nil [nil] nil
168
- # # yield [1, 2] [[1, 2]] [1, 2]
169
- # ```
170
- #
171
- # Note that `next_values` does not affect other non-external enumeration
172
- # methods unless underlying iteration method itself has side-effect, e.g.
173
- # [IO\#each\_line](https://ruby-doc.org/core-2.6.3/IO.html#method-i-each_line)
174
- # .
175
- def next_values: () -> ::Array[Elem]
176
-
177
- # Returns the next object in the enumerator, but doesn’t move the internal
178
- # position forward. If the position is already at the end,
179
- # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html) is
180
- # raised.
181
- #
182
- #
183
- # ```ruby
184
- # a = [1,2,3]
185
- # e = a.to_enum
186
- # p e.next #=> 1
187
- # p e.peek #=> 2
188
- # p e.peek #=> 2
189
- # p e.peek #=> 2
190
- # p e.next #=> 2
191
- # p e.next #=> 3
192
- # p e.peek #raises StopIteration
193
- # ```
194
- def peek: () -> Elem
195
-
196
- # Returns the next object as an array, similar to
197
- # [\#next\_values](Enumerator.downloaded.ruby_doc#method-i-next_values),
198
- # but doesn’t move the internal position forward. If the position is
199
- # already at the end,
200
- # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html) is
201
- # raised.
202
- #
203
- #
204
- # ```ruby
205
- # o = Object.new
206
- # def o.each
207
- # yield
208
- # yield 1
209
- # yield 1, 2
210
- # end
211
- # e = o.to_enum
212
- # p e.peek_values #=> []
213
- # e.next
214
- # p e.peek_values #=> [1]
215
- # p e.peek_values #=> [1]
216
- # e.next
217
- # p e.peek_values #=> [1, 2]
218
- # e.next
219
- # p e.peek_values # raises StopIteration
220
- # ```
221
- def peek_values: () -> ::Array[Elem]
222
-
223
- # Rewinds the enumeration sequence to the beginning.
224
- #
225
- # If the enclosed object responds to a “rewind” method, it is called.
226
- def rewind: () -> self
227
-
228
- # Returns the size of the enumerator, or `nil` if it can’t be calculated
229
- # lazily.
230
- #
231
- # ```ruby
232
- # (1..100).to_a.permutation(4).size # => 94109400
233
- # loop.size # => Float::INFINITY
234
- # (1..100).drop_while.size # => nil
235
- # ```
236
- def size: () -> (Integer | Float)?
237
-
238
- def with_index: (?Integer offset) { (Elem arg0, Integer arg1) -> untyped } -> Return
239
- | (?Integer offset) -> ::Enumerator[[ Elem, Integer ], Return]
240
-
241
- def with_object: [U] (U arg0) { (Elem arg0, U arg1) -> untyped } -> U
242
- | [U] (U arg0) -> ::Enumerator[[ Elem, U ], Return]
243
- end
244
-
245
- class Enumerator::Generator[out Elem, out Return] < Object
246
- include Enumerable[Elem, Return]
247
- end
248
-
249
- class Enumerator::Lazy[out Elem, out Return] < Enumerator[Elem, Return]
250
- end
251
-
252
- class Enumerator::Yielder < Object
253
- def <<: (*untyped arg0) -> void
254
-
255
- def yield: (*untyped arg0) -> void
256
- end
257
-
258
- class Enumerator::Chain[out Elem, out Return] < Object
259
- include Enumerable[Elem, Return]
260
- end