steep 0.16.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +24 -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 +1 -1
  9. data/lib/steep/drivers/check.rb +1 -12
  10. data/lib/steep/drivers/watch.rb +2 -2
  11. data/lib/steep/project/file.rb +1 -1
  12. data/lib/steep/project/hover_content.rb +1 -1
  13. data/lib/steep/project/options.rb +15 -0
  14. data/lib/steep/server/code_worker.rb +4 -4
  15. data/lib/steep/server/signature_worker.rb +4 -4
  16. data/lib/steep/type_construction.rb +13 -19
  17. data/lib/steep/type_inference/constant_env.rb +2 -10
  18. data/lib/steep/type_inference/context.rb +1 -0
  19. data/lib/steep/version.rb +1 -1
  20. data/steep.gemspec +6 -7
  21. metadata +23 -146
  22. data/exe/rbs +0 -3
  23. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  24. data/vendor/ruby-signature/.gitignore +0 -12
  25. data/vendor/ruby-signature/.rubocop.yml +0 -15
  26. data/vendor/ruby-signature/BSDL +0 -22
  27. data/vendor/ruby-signature/COPYING +0 -56
  28. data/vendor/ruby-signature/Gemfile +0 -6
  29. data/vendor/ruby-signature/README.md +0 -93
  30. data/vendor/ruby-signature/Rakefile +0 -142
  31. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
  32. data/vendor/ruby-signature/bin/console +0 -14
  33. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  34. data/vendor/ruby-signature/bin/setup +0 -10
  35. data/vendor/ruby-signature/bin/sort +0 -89
  36. data/vendor/ruby-signature/bin/test_runner.rb +0 -16
  37. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  38. data/vendor/ruby-signature/docs/sigs.md +0 -148
  39. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  40. data/vendor/ruby-signature/docs/syntax.md +0 -528
  41. data/vendor/ruby-signature/exe/rbs +0 -7
  42. data/vendor/ruby-signature/lib/rbs.rb +0 -64
  43. data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
  44. data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
  45. data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
  46. data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
  47. data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
  48. data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
  49. data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
  50. data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
  51. data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
  52. data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
  53. data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
  54. data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
  55. data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
  56. data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
  57. data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
  58. data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
  59. data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
  60. data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
  61. data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
  62. data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
  63. data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
  64. data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
  65. data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
  66. data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
  67. data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
  68. data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
  69. data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
  70. data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
  71. data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
  72. data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
  73. data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
  74. data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
  75. data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
  76. data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
  77. data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
  78. data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
  79. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
  80. data/vendor/ruby-signature/rbs.gemspec +0 -46
  81. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
  82. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
  83. data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
  84. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  85. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  86. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  87. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -45
  88. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  89. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  90. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  91. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  92. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  93. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  94. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -413
  95. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
  96. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  97. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  98. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  99. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  100. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -194
  101. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  102. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  103. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  104. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -1076
  105. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  106. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  107. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -243
  108. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  109. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
  110. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  111. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
  112. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
  113. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
  114. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
  115. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
  116. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
  117. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  118. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  119. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  120. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -429
  121. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
  122. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
  123. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  124. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  125. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -57
  126. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
  127. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  128. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  129. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1901
  130. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
  131. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  132. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
  133. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
  134. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  135. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
  136. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
  137. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  138. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
  139. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  140. data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
  141. data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
  142. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
  143. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
  144. data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
  145. data/vendor/ruby-signature/stdlib/json/json.rbs +0 -335
  146. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
  147. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  148. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  149. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  150. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -301
  151. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,267 +0,0 @@
1
- # Random provides an interface to Ruby's pseudo-random number generator, or
2
- # PRNG. The PRNG produces a deterministic sequence of bits which approximate
3
- # true randomness. The sequence may be represented by integers, floats, or
4
- # binary strings.
5
- #
6
- # The generator may be initialized with either a system-generated or
7
- # user-supplied seed value by using Random.srand.
8
- #
9
- # The class method Random.rand provides the base functionality of Kernel.rand
10
- # along with better handling of floating point values. These are both interfaces
11
- # to Random::DEFAULT, the Ruby system PRNG.
12
- #
13
- # Random.new will create a new PRNG with a state independent of Random::DEFAULT,
14
- # allowing multiple generators with different seed values or sequence positions
15
- # to exist simultaneously. Random objects can be marshaled, allowing sequences
16
- # to be saved and resumed.
17
- #
18
- # PRNGs are currently implemented as a modified Mersenne Twister with a period
19
- # of 2**19937-1.
20
- #
21
- class Random < Object
22
- include Random::Formatter
23
-
24
- # Returns true if the two generators have the same internal state, otherwise
25
- # false. Equivalent generators will return the same sequence of pseudo-random
26
- # numbers. Two generators will generally have the same state only if they were
27
- # initialized with the same seed
28
- #
29
- # Random.new == Random.new # => false
30
- # Random.new(1234) == Random.new(1234) # => true
31
- #
32
- # and have the same invocation history.
33
- #
34
- # prng1 = Random.new(1234)
35
- # prng2 = Random.new(1234)
36
- # prng1 == prng2 # => true
37
- #
38
- # prng1.rand # => 0.1915194503788923
39
- # prng1 == prng2 # => false
40
- #
41
- # prng2.rand # => 0.1915194503788923
42
- # prng1 == prng2 # => true
43
- #
44
- def ==: (untyped arg0) -> bool
45
-
46
- # Returns a random binary string containing `size` bytes.
47
- #
48
- # random_string = Random.new.bytes(10) # => "\xD7:R\xAB?\x83\xCE\xFAkO"
49
- # random_string.size # => 10
50
- #
51
- def bytes: (Integer size) -> String
52
-
53
- # Creates a new PRNG using `seed` to set the initial state. If `seed` is
54
- # omitted, the generator is initialized with Random.new_seed.
55
- #
56
- # See Random.srand for more information on the use of seed values.
57
- #
58
- def initialize: (?Integer seed) -> void
59
-
60
- # When `max` is an Integer, `rand` returns a random integer greater than or
61
- # equal to zero and less than `max`. Unlike Kernel.rand, when `max` is a
62
- # negative integer or zero, `rand` raises an ArgumentError.
63
- #
64
- # prng = Random.new
65
- # prng.rand(100) # => 42
66
- #
67
- # When `max` is a Float, `rand` returns a random floating point number between
68
- # 0.0 and `max`, including 0.0 and excluding `max`.
69
- #
70
- # prng.rand(1.5) # => 1.4600282860034115
71
- #
72
- # When `max` is a Range, `rand` returns a random number where
73
- # range.member?(number) == true.
74
- #
75
- # prng.rand(5..9) # => one of [5, 6, 7, 8, 9]
76
- # prng.rand(5...9) # => one of [5, 6, 7, 8]
77
- # prng.rand(5.0..9.0) # => between 5.0 and 9.0, including 9.0
78
- # prng.rand(5.0...9.0) # => between 5.0 and 9.0, excluding 9.0
79
- #
80
- # Both the beginning and ending values of the range must respond to subtract
81
- # (`-`) and add (`+`)methods, or rand will raise an ArgumentError.
82
- #
83
- def rand: () -> Float
84
- | (Integer | ::Range[Integer] max) -> Integer
85
- | (Float | ::Range[Float] max) -> Float
86
-
87
- # Returns the seed value used to initialize the generator. This may be used to
88
- # initialize another generator with the same state at a later time, causing it
89
- # to produce the same sequence of numbers.
90
- #
91
- # prng1 = Random.new(1234)
92
- # prng1.seed #=> 1234
93
- # prng1.rand(100) #=> 47
94
- #
95
- # prng2 = Random.new(prng1.seed)
96
- # prng2.rand(100) #=> 47
97
- #
98
- def seed: () -> Integer
99
-
100
- # Returns an arbitrary seed value. This is used by Random.new when no seed value
101
- # is specified as an argument.
102
- #
103
- # Random.new_seed #=> 115032730400174366788466674494640623225
104
- #
105
- def self.new_seed: () -> Integer
106
-
107
- # Alias of Random::DEFAULT.rand.
108
- #
109
- def self.rand: (?Integer max) -> Numeric
110
-
111
- # Seeds the system pseudo-random number generator, Random::DEFAULT, with
112
- # `number`. The previous seed value is returned.
113
- #
114
- # If `number` is omitted, seeds the generator using a source of entropy provided
115
- # by the operating system, if available (/dev/urandom on Unix systems or the RSA
116
- # cryptographic provider on Windows), which is then combined with the time, the
117
- # process id, and a sequence number.
118
- #
119
- # srand may be used to ensure repeatable sequences of pseudo-random numbers
120
- # between different runs of the program. By setting the seed to a known value,
121
- # programs can be made deterministic during testing.
122
- #
123
- # srand 1234 # => 268519324636777531569100071560086917274
124
- # [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
125
- # [ rand(10), rand(1000) ] # => [4, 664]
126
- # srand 1234 # => 1234
127
- # [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
128
- #
129
- def self.srand: (?Integer number) -> Numeric
130
- end
131
-
132
- # The default Pseudorandom number generator. Used by class methods of Random.
133
- #
134
- #
135
- Random::DEFAULT: Random
136
-
137
- # Format raw random number as Random does
138
- #
139
- #
140
- module Random::Formatter
141
- # SecureRandom.base64 generates a random base64 string.
142
- #
143
- # The argument *n* specifies the length, in bytes, of the random number to be
144
- # generated. The length of the result string is about 4/3 of *n*.
145
- #
146
- # If *n* is not specified or is nil, 16 is assumed. It may be larger in the
147
- # future.
148
- #
149
- # The result may contain A-Z, a-z, 0-9, "+", "/" and "=".
150
- #
151
- # require 'securerandom'
152
- #
153
- # SecureRandom.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A=="
154
- # SecureRandom.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="
155
- #
156
- # If a secure random number generator is not available, `NotImplementedError` is
157
- # raised.
158
- #
159
- # See RFC 3548 for the definition of base64.
160
- #
161
- def base64: (?Integer? n) -> String
162
-
163
- # SecureRandom.hex generates a random hexadecimal string.
164
- #
165
- # The argument *n* specifies the length, in bytes, of the random number to be
166
- # generated. The length of the resulting hexadecimal string is twice of *n*.
167
- #
168
- # If *n* is not specified or is nil, 16 is assumed. It may be larger in the
169
- # future.
170
- #
171
- # The result may contain 0-9 and a-f.
172
- #
173
- # require 'securerandom'
174
- #
175
- # SecureRandom.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
176
- # SecureRandom.hex #=> "91dc3bfb4de5b11d029d376634589b61"
177
- #
178
- # If a secure random number generator is not available, `NotImplementedError` is
179
- # raised.
180
- #
181
- def hex: (?Integer? n) -> String
182
-
183
- # Generates formatted random number from raw random bytes. See Random#rand.
184
- #
185
- def rand: () -> Float
186
- | (?Float? n) -> Float
187
- | (?Integer? n) -> Integer
188
- | (?Numeric? n) -> Numeric
189
- | (?::Range[Float]? n) -> Float
190
- | (?::Range[Integer]? n) -> Integer
191
- | (?::Range[Numeric]? n) -> Numeric
192
-
193
- # SecureRandom.random_bytes generates a random binary string.
194
- #
195
- # The argument *n* specifies the length of the result string.
196
- #
197
- # If *n* is not specified or is nil, 16 is assumed. It may be larger in future.
198
- #
199
- # The result may contain any byte: "x00" - "xff".
200
- #
201
- # require 'securerandom'
202
- #
203
- # SecureRandom.random_bytes #=> "\xD8\\\xE0\xF4\r\xB2\xFC*WM\xFF\x83\x18\xF45\xB6"
204
- # SecureRandom.random_bytes #=> "m\xDC\xFC/\a\x00Uf\xB2\xB2P\xBD\xFF6S\x97"
205
- #
206
- # If a secure random number generator is not available, `NotImplementedError` is
207
- # raised.
208
- #
209
- def random_bytes: (?Integer? n) -> String
210
-
211
- # Generates formatted random number from raw random bytes. See Random#rand.
212
- #
213
- def random_number: () -> Float
214
- | (?Float? n) -> Float
215
- | (?Integer? n) -> Integer
216
- | (?Numeric? n) -> Numeric
217
- | (?::Range[Float]? n) -> Float
218
- | (?::Range[Integer]? n) -> Integer
219
- | (?::Range[Numeric]? n) -> Numeric
220
-
221
- # SecureRandom.urlsafe_base64 generates a random URL-safe base64 string.
222
- #
223
- # The argument *n* specifies the length, in bytes, of the random number to be
224
- # generated. The length of the result string is about 4/3 of *n*.
225
- #
226
- # If *n* is not specified or is nil, 16 is assumed. It may be larger in the
227
- # future.
228
- #
229
- # The boolean argument *padding* specifies the padding. If it is false or nil,
230
- # padding is not generated. Otherwise padding is generated. By default, padding
231
- # is not generated because "=" may be used as a URL delimiter.
232
- #
233
- # The result may contain A-Z, a-z, 0-9, "-" and "_". "=" is also used if
234
- # *padding* is true.
235
- #
236
- # require 'securerandom'
237
- #
238
- # SecureRandom.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
239
- # SecureRandom.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
240
- #
241
- # SecureRandom.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
242
- # SecureRandom.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
243
- #
244
- # If a secure random number generator is not available, `NotImplementedError` is
245
- # raised.
246
- #
247
- # See RFC 3548 for the definition of URL-safe base64.
248
- #
249
- def urlsafe_base64: (?Integer? n, ?bool padding) -> String
250
-
251
- # SecureRandom.uuid generates a random v4 UUID (Universally Unique IDentifier).
252
- #
253
- # require 'securerandom'
254
- #
255
- # SecureRandom.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
256
- # SecureRandom.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
257
- # SecureRandom.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
258
- #
259
- # The version 4 UUID is purely random (except the version). It doesn't contain
260
- # meaningful information such as MAC addresses, timestamps, etc.
261
- #
262
- # The result contains 122 random bits (15.25 random bytes).
263
- #
264
- # See RFC 4122 for details of UUID.
265
- #
266
- def uuid: () -> String
267
- end
@@ -1,226 +0,0 @@
1
- # A `Range` represents an interval—a set of values with a beginning and an
2
- # end. Ranges may be constructed using the *s* `..` *e* and *s* `...` *e*
3
- # literals, or with [::new](Range#method-c-new).
4
- # Ranges constructed using `..` run from the beginning to the end
5
- # inclusively. Those created using `...` exclude the end value. When used
6
- # as an iterator, ranges return each value in the sequence.
7
- #
8
- # ```ruby
9
- # (-1..-5).to_a #=> []
10
- # (-5..-1).to_a #=> [-5, -4, -3, -2, -1]
11
- # ('a'..'e').to_a #=> ["a", "b", "c", "d", "e"]
12
- # ('a'...'e').to_a #=> ["a", "b", "c", "d"]
13
- # ```
14
- #
15
- #
16
- # An “endless range” represents a semi-infinite range. Literal notation
17
- # for an endless range is:
18
- #
19
- # (1..)
20
- # # or similarly
21
- # (1...)
22
- #
23
- # Which is equivalent to
24
- #
25
- # ```ruby
26
- # (1..nil) # or similarly (1...nil)
27
- # Range.new(1, nil) # or Range.new(1, nil, true)
28
- # ```
29
- #
30
- # Endless ranges are useful, for example, for idiomatic slicing of arrays:
31
- #
32
- # [1, 2, 3, 4, 5][2...] # => [3, 4, 5]
33
- #
34
- # Some implementation details:
35
- #
36
- # - `end` of endless range is `nil` ;
37
- #
38
- # - `each` of endless range enumerates infinite sequence (may be useful
39
- # in combination with
40
- # [Enumerable\#take\_while](https://ruby-doc.org/core-2.6.3/Enumerable.html#method-i-take_while)
41
- # or similar methods);
42
- #
43
- # - `(1..)` and `(1...)` are not equal, although technically
44
- # representing the same sequence.
45
- #
46
- #
47
- # Ranges can be constructed using any objects that can be compared using
48
- # the `<=>` operator. Methods that treat the range as a sequence (\#each
49
- # and methods inherited from
50
- # [Enumerable](https://ruby-doc.org/core-2.6.3/Enumerable.html) ) expect
51
- # the begin object to implement a `succ` method to return the next object
52
- # in sequence. The [step](Range#method-i-step) and
53
- # [include?](Range#method-i-include-3F) methods
54
- # require the begin object to implement `succ` or to be numeric.
55
- #
56
- # In the `Xs` class below both `<=>` and `succ` are implemented so `Xs`
57
- # can be used to construct ranges. Note that the
58
- # [Comparable](https://ruby-doc.org/core-2.6.3/Comparable.html) module is
59
- # included so the `==` method is defined in terms of `<=>` .
60
- #
61
- # ```ruby
62
- # class Xs # represent a string of 'x's
63
- # include Comparable
64
- # attr :length
65
- # def initialize(n)
66
- # @length = n
67
- # end
68
- # def succ
69
- # Xs.new(@length + 1)
70
- # end
71
- # def <=>(other)
72
- # @length <=> other.length
73
- # end
74
- # def to_s
75
- # sprintf "%2d #{inspect}", @length
76
- # end
77
- # def inspect
78
- # 'x' * @length
79
- # end
80
- # end
81
- # ```
82
- #
83
- # An example of using `Xs` to construct a range:
84
- #
85
- # ```ruby
86
- # r = Xs.new(3)..Xs.new(6) #=> xxx..xxxxxx
87
- # r.to_a #=> [xxx, xxxx, xxxxx, xxxxxx]
88
- # r.member?(Xs.new(5)) #=> true
89
- # ```
90
- class Range[Elem] < Object
91
- include Enumerable[Elem, Range[Elem]]
92
-
93
- def self.new: [U] (U from, U to, ?bool exclude_end) -> ::Range[U]
94
-
95
- def ==: (untyped obj) -> bool
96
-
97
- def ===: (untyped obj) -> bool
98
-
99
- # Returns the object that defines the beginning of the range.
100
- #
101
- # ```ruby
102
- # (1..10).begin #=> 1
103
- # ```
104
- def begin: () -> Elem
105
-
106
- def bsearch: [U] () { (Elem arg0) -> bool } -> U?
107
-
108
- def cover?: (untyped obj) -> bool
109
-
110
- def each: () { (Elem arg0) -> untyped } -> self
111
- | () -> ::Enumerator[Elem, self]
112
-
113
- # Returns the object that defines the end of the range.
114
- #
115
- # ```ruby
116
- # (1..10).end #=> 10
117
- # (1...10).end #=> 10
118
- # ```
119
- def `end`: () -> Elem
120
-
121
- # Returns `true` if the range excludes its end value.
122
- #
123
- # ```ruby
124
- # (1..5).exclude_end? #=> false
125
- # (1...5).exclude_end? #=> true
126
- # ```
127
- def `exclude_end?`: () -> bool
128
-
129
- # Returns the first object in the range, or an array of the first `n`
130
- # elements.
131
- #
132
- # ```ruby
133
- # (10..20).first #=> 10
134
- # (10..20).first(3) #=> [10, 11, 12]
135
- # ```
136
- def first: () -> Elem
137
- | (?Integer n) -> ::Array[Elem]
138
-
139
- # Compute a hash-code for this range. Two ranges with equal begin and end
140
- # points (using `eql?` ), and the same
141
- # [exclude\_end?](Range.downloaded.ruby_doc#method-i-exclude_end-3F) value
142
- # will generate the same hash-code.
143
- #
144
- # See also Object\#hash.
145
- def hash: () -> Integer
146
-
147
- def `include?`: (untyped obj) -> bool
148
-
149
- def initialize: (Elem _begin, Elem _end, ?bool exclude_end) -> void
150
-
151
- # Convert this range object to a printable form (using `inspect` to
152
- # convert the begin and end objects).
153
- def inspect: () -> String
154
-
155
- # Returns the last object in the range, or an array of the last `n`
156
- # elements.
157
- #
158
- # Note that with no arguments `last` will return the object that defines
159
- # the end of the range even if
160
- # [exclude\_end?](Range.downloaded.ruby_doc#method-i-exclude_end-3F) is
161
- # `true` .
162
- #
163
- # ```ruby
164
- # (10..20).last #=> 20
165
- # (10...20).last #=> 20
166
- # (10..20).last(3) #=> [18, 19, 20]
167
- # (10...20).last(3) #=> [17, 18, 19]
168
- # ```
169
- def last: () -> Elem
170
- | (?Integer n) -> ::Array[Elem]
171
-
172
- # Returns the maximum value in the range. Returns `nil` if the begin value
173
- # of the range larger than the end value. Returns `nil` if the begin value
174
- # of an exclusive range is equal to the end value.
175
- #
176
- # Can be given an optional block to override the default comparison method
177
- # `a <=> b` .
178
- #
179
- # ```ruby
180
- # (10..20).max #=> 20
181
- # ```
182
- def max: () -> Elem
183
- | () { (Elem arg0, Elem arg1) -> Integer } -> Elem
184
- | (?Integer n) -> ::Array[Elem]
185
- | (?Integer n) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
186
-
187
- # Returns the minimum value in the range. Returns `nil` if the begin value
188
- # of the range is larger than the end value. Returns `nil` if the begin
189
- # value of an exclusive range is equal to the end value.
190
- #
191
- # Can be given an optional block to override the default comparison method
192
- # `a <=> b` .
193
- #
194
- # ```ruby
195
- # (10..20).min #=> 10
196
- # ```
197
- def min: () -> Elem
198
- | () { (Elem arg0, Elem arg1) -> Integer } -> Elem
199
- | (?Integer n) -> ::Array[Elem]
200
- | (?Integer n) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
201
-
202
- # Returns the number of elements in the range. Both the begin and the end
203
- # of the [Range](Range.downloaded.ruby_doc) must be
204
- # [Numeric](https://ruby-doc.org/core-2.6.3/Numeric.html), otherwise nil
205
- # is returned.
206
- #
207
- # ```ruby
208
- # (10..20).size #=> 11
209
- # ('a'..'z').size #=> nil
210
- # (-Float::INFINITY..Float::INFINITY).size #=> Infinity
211
- # ```
212
- def size: () -> Integer?
213
- | () -> Float?
214
-
215
- def step: (?Integer n) { (Elem arg0) -> untyped } -> self
216
- | (?Integer n) -> ::Enumerator[Elem, void]
217
-
218
- # Convert this range object to a printable form (using
219
- # [to\_s](Range.downloaded.ruby_doc#method-i-to_s) to convert the begin
220
- # and end objects).
221
- def to_s: () -> String
222
-
223
- def eql?: (untyped obj) -> bool
224
-
225
- def member?: (untyped obj) -> bool
226
- end