steep 0.14.0 → 0.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +25 -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 +18 -2
  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 +55 -55
  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/langserver.rb +13 -457
  17. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  18. data/lib/steep/drivers/vendor.rb +2 -2
  19. data/lib/steep/drivers/watch.rb +97 -85
  20. data/lib/steep/drivers/worker.rb +51 -0
  21. data/lib/steep/project.rb +9 -5
  22. data/lib/steep/project/completion_provider.rb +9 -13
  23. data/lib/steep/project/dsl.rb +14 -0
  24. data/lib/steep/project/file.rb +43 -46
  25. data/lib/steep/project/hover_content.rb +17 -8
  26. data/lib/steep/project/options.rb +25 -3
  27. data/lib/steep/project/target.rb +40 -24
  28. data/lib/steep/server/base_worker.rb +56 -0
  29. data/lib/steep/server/code_worker.rb +151 -0
  30. data/lib/steep/server/interaction_worker.rb +281 -0
  31. data/lib/steep/server/master.rb +196 -0
  32. data/lib/steep/server/signature_worker.rb +148 -0
  33. data/lib/steep/server/utils.rb +36 -0
  34. data/lib/steep/server/worker_process.rb +62 -0
  35. data/lib/steep/signature/errors.rb +1 -1
  36. data/lib/steep/signature/validator.rb +13 -13
  37. data/lib/steep/source.rb +1 -1
  38. data/lib/steep/type_construction.rb +996 -726
  39. data/lib/steep/type_inference/constant_env.rb +3 -11
  40. data/lib/steep/type_inference/context.rb +8 -3
  41. data/lib/steep/type_inference/context_array.rb +111 -0
  42. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  43. data/lib/steep/type_inference/logic.rb +130 -0
  44. data/lib/steep/type_inference/type_env.rb +5 -69
  45. data/lib/steep/typing.rb +79 -22
  46. data/lib/steep/version.rb +1 -1
  47. data/smoke/alias/Steepfile +1 -0
  48. data/smoke/and/Steepfile +1 -0
  49. data/smoke/array/Steepfile +1 -0
  50. data/smoke/array/b.rb +0 -2
  51. data/smoke/block/Steepfile +1 -0
  52. data/smoke/case/Steepfile +1 -0
  53. data/smoke/class/Steepfile +1 -0
  54. data/smoke/const/Steepfile +1 -0
  55. data/smoke/dstr/Steepfile +1 -0
  56. data/smoke/ensure/Steepfile +1 -0
  57. data/smoke/enumerator/Steepfile +1 -0
  58. data/smoke/extension/Steepfile +1 -0
  59. data/smoke/extension/c.rb +1 -0
  60. data/smoke/hash/Steepfile +1 -0
  61. data/smoke/hello/Steepfile +1 -0
  62. data/smoke/if/Steepfile +1 -0
  63. data/smoke/if/a.rb +1 -1
  64. data/smoke/implements/Steepfile +1 -0
  65. data/smoke/initialize/Steepfile +1 -0
  66. data/smoke/integer/Steepfile +1 -0
  67. data/smoke/interface/Steepfile +1 -0
  68. data/smoke/kwbegin/Steepfile +1 -0
  69. data/smoke/lambda/Steepfile +1 -0
  70. data/smoke/literal/Steepfile +1 -0
  71. data/smoke/map/Steepfile +1 -0
  72. data/smoke/method/Steepfile +1 -0
  73. data/smoke/module/Steepfile +1 -0
  74. data/smoke/regexp/Steepfile +1 -0
  75. data/smoke/regression/Steepfile +1 -0
  76. data/smoke/rescue/Steepfile +1 -0
  77. data/smoke/rescue/a.rb +1 -1
  78. data/smoke/self/Steepfile +1 -0
  79. data/smoke/skip/Steepfile +1 -0
  80. data/smoke/stdout/Steepfile +1 -0
  81. data/smoke/super/Steepfile +1 -0
  82. data/smoke/type_case/Steepfile +1 -0
  83. data/smoke/yield/Steepfile +1 -0
  84. data/steep.gemspec +7 -8
  85. metadata +26 -141
  86. data/exe/rbs +0 -3
  87. data/exe/ruby-signature +0 -3
  88. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  89. data/vendor/ruby-signature/.gitignore +0 -12
  90. data/vendor/ruby-signature/.rubocop.yml +0 -15
  91. data/vendor/ruby-signature/BSDL +0 -22
  92. data/vendor/ruby-signature/COPYING +0 -56
  93. data/vendor/ruby-signature/Gemfile +0 -6
  94. data/vendor/ruby-signature/README.md +0 -93
  95. data/vendor/ruby-signature/Rakefile +0 -67
  96. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
  97. data/vendor/ruby-signature/bin/console +0 -14
  98. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  99. data/vendor/ruby-signature/bin/setup +0 -10
  100. data/vendor/ruby-signature/bin/sort +0 -88
  101. data/vendor/ruby-signature/bin/test_runner.rb +0 -17
  102. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  103. data/vendor/ruby-signature/docs/sigs.md +0 -148
  104. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  105. data/vendor/ruby-signature/docs/syntax.md +0 -528
  106. data/vendor/ruby-signature/exe/rbs +0 -3
  107. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  108. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
  109. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  110. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  111. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  112. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  113. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  114. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  115. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -555
  116. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  117. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  118. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  119. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  120. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  121. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  122. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  123. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  124. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  125. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  126. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  127. data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1344
  128. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
  129. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  130. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  131. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  132. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  133. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  134. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  135. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
  136. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -327
  137. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  138. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  139. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  140. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  141. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  142. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  143. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  144. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
  145. data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
  146. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
  147. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
  148. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  149. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  150. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  151. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
  152. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  153. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  154. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  155. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  156. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  157. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  158. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
  159. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
  160. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  161. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  162. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  163. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  164. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
  165. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  166. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  167. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  168. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
  169. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  170. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  171. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
  172. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  173. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
  174. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  175. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
  176. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
  177. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
  178. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
  179. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
  180. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
  181. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  182. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  183. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  184. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
  185. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
  186. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
  187. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  188. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  189. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
  190. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
  191. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  192. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  193. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1894
  194. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
  195. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  196. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
  197. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
  198. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  199. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
  200. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
  201. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  202. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
  203. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  204. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
  205. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
  206. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
  207. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  208. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  209. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  210. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
  211. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,710 +0,0 @@
1
- # Holds Integer values. You cannot add a singleton method to an Integer object,
2
- # any attempt to do so will raise a TypeError.
3
- #
4
- class Integer < Numeric
5
- # Returns the integer square root of the non-negative integer `n`, i.e. the
6
- # largest non-negative integer less than or equal to the square root of `n`.
7
- #
8
- # Integer.sqrt(0) #=> 0
9
- # Integer.sqrt(1) #=> 1
10
- # Integer.sqrt(24) #=> 4
11
- # Integer.sqrt(25) #=> 5
12
- # Integer.sqrt(10**400) #=> 10**200
13
- #
14
- # Equivalent to `Math.sqrt(n).floor`, except that the result of the latter code
15
- # may differ from the true value due to the limited precision of floating point
16
- # arithmetic.
17
- #
18
- # Integer.sqrt(10**46) #=> 100000000000000000000000
19
- # Math.sqrt(10**46).floor #=> 99999999999999991611392 (!)
20
- #
21
- # If `n` is not an Integer, it is converted to an Integer first. If `n` is
22
- # negative, a Math::DomainError is raised.
23
- #
24
- def self.sqrt: (int n) -> Integer
25
-
26
- public
27
-
28
- # Returns `int` modulo `other`.
29
- #
30
- # See Numeric#divmod for more information.
31
- #
32
- def %: (Float) -> Float
33
- | (Rational) -> Rational
34
- | (Integer) -> Integer
35
- | (Numeric) -> Numeric
36
-
37
- # Bitwise AND.
38
- #
39
- def &: (Integer) -> Integer
40
-
41
- # Performs multiplication: the class of the resulting object depends on the
42
- # class of `numeric`.
43
- #
44
- def *: (Float) -> Float
45
- | (Rational) -> Rational
46
- | (Complex) -> Complex
47
- | (Integer) -> Integer
48
- | (Numeric) -> Numeric
49
-
50
- # Raises `int` to the power of `numeric`, which may be negative or fractional.
51
- # The result may be an Integer, a Float, a Rational, or a complex number.
52
- #
53
- # 2 ** 3 #=> 8
54
- # 2 ** -1 #=> (1/2)
55
- # 2 ** 0.5 #=> 1.4142135623730951
56
- # (-1) ** 0.5 #=> (0.0+1.0i)
57
- #
58
- # 123456789 ** 2 #=> 15241578750190521
59
- # 123456789 ** 1.2 #=> 5126464716.0993185
60
- # 123456789 ** -2 #=> (1/15241578750190521)
61
- #
62
- def **: (Integer) -> Numeric
63
- | (Float) -> Numeric
64
- | (Rational) -> Numeric
65
- | (Complex) -> Complex
66
- | (Numeric) -> Numeric
67
-
68
- # Performs addition: the class of the resulting object depends on the class of
69
- # `numeric`.
70
- #
71
- def +: (Integer) -> Integer
72
- | (Float) -> Float
73
- | (Rational) -> Rational
74
- | (Complex) -> Complex
75
- | (Numeric) -> Numeric
76
-
77
- def +@: () -> Integer
78
-
79
- # Performs subtraction: the class of the resulting object depends on the class
80
- # of `numeric`.
81
- #
82
- def -: (Integer) -> Integer
83
- | (Float) -> Float
84
- | (Rational) -> Rational
85
- | (Complex) -> Complex
86
- | (Numeric) -> Numeric
87
-
88
- # Returns `int`, negated.
89
- #
90
- def -@: () -> Integer
91
-
92
- # Performs division: the class of the resulting object depends on the class of
93
- # `numeric`.
94
- #
95
- def /: (Integer) -> Integer
96
- | (Float) -> Float
97
- | (Rational) -> Rational
98
- | (Complex) -> Complex
99
- | (Numeric) -> Numeric
100
-
101
- # Returns `true` if the value of `int` is less than that of `real`.
102
- #
103
- def <: (Numeric) -> bool
104
-
105
- # Returns `int` shifted left `count` positions, or right if `count` is negative.
106
- #
107
- def <<: (int) -> Integer
108
-
109
- # Returns `true` if the value of `int` is less than or equal to that of `real`.
110
- #
111
- def <=: (Numeric) -> bool
112
-
113
- # Comparison---Returns -1, 0, or +1 depending on whether `int` is less than,
114
- # equal to, or greater than `numeric`.
115
- #
116
- # This is the basis for the tests in the Comparable module.
117
- #
118
- # `nil` is returned if the two values are incomparable.
119
- #
120
- def <=>: (Numeric) -> Integer?
121
-
122
- # Returns `true` if `int` equals `other` numerically. Contrast this with
123
- # Integer#eql?, which requires `other` to be an Integer.
124
- #
125
- # 1 == 2 #=> false
126
- # 1 == 1.0 #=> true
127
- #
128
- def ==: (untyped) -> bool
129
-
130
- # Returns `true` if `int` equals `other` numerically. Contrast this with
131
- # Integer#eql?, which requires `other` to be an Integer.
132
- #
133
- # 1 == 2 #=> false
134
- # 1 == 1.0 #=> true
135
- #
136
- def ===: (untyped) -> bool
137
-
138
- # Returns `true` if the value of `int` is greater than that of `real`.
139
- #
140
- def >: (Numeric) -> bool
141
-
142
- # Returns `true` if the value of `int` is greater than or equal to that of
143
- # `real`.
144
- #
145
- def >=: (Numeric) -> bool
146
-
147
- # Returns `int` shifted right `count` positions, or left if `count` is negative.
148
- #
149
- def >>: (int) -> Integer
150
-
151
- # Bit Reference---Returns the `n`th bit in the binary representation of `int`,
152
- # where `int[0]` is the least significant bit.
153
- #
154
- # a = 0b11001100101010
155
- # 30.downto(0) {|n| print a[n] }
156
- # #=> 0000000000000000011001100101010
157
- #
158
- # a = 9**15
159
- # 50.downto(0) {|n| print a[n] }
160
- # #=> 000101110110100000111000011110010100111100010111001
161
- #
162
- # In principle, `n[i]` is equivalent to `(n >> i) & 1`. Thus, any negative index
163
- # always returns zero:
164
- #
165
- # p 255[-1] #=> 0
166
- #
167
- # Range operations `n[i, len]` and `n[i..j]` are naturally extended.
168
- #
169
- # * `n[i, len]` equals to `(n >> i) & ((1 << len) - 1)`.
170
- # * `n[i..j]` equals to `(n >> i) & ((1 << (j - i + 1)) - 1)`.
171
- # * `n[i...j]` equals to `(n >> i) & ((1 << (j - i)) - 1)`.
172
- # * `n[i..]` equals to `(n >> i)`.
173
- # * `n[..j]` is zero if `n & ((1 << (j + 1)) - 1)` is zero. Otherwise, raises
174
- # an ArgumentError.
175
- # * `n[...j]` is zero if `n & ((1 << j) - 1)` is zero. Otherwise, raises an
176
- # ArgumentError.
177
- #
178
- #
179
- # Note that range operation may exhaust memory. For example, `-1[0,
180
- # 1000000000000]` will raise NoMemoryError.
181
- #
182
- def []: (int) -> Integer
183
- | (int i, int len) -> Integer
184
- | (Range[int]) -> Integer
185
-
186
- # Bitwise EXCLUSIVE OR.
187
- #
188
- def ^: (Integer) -> Integer
189
-
190
- # Returns the absolute value of `int`.
191
- #
192
- # (-12345).abs #=> 12345
193
- # -12345.abs #=> 12345
194
- # 12345.abs #=> 12345
195
- #
196
- # Integer#magnitude is an alias for Integer#abs.
197
- #
198
- def abs: () -> Integer
199
-
200
- def abs2: () -> Integer
201
-
202
- # Returns `true` if all bits of `int & mask` are 1.
203
- #
204
- def allbits?: (int mask) -> bool
205
-
206
- def angle: () -> (Integer | Float)
207
-
208
- # Returns `true` if any bits of `int & mask` are 1.
209
- #
210
- def anybits?: (int mask) -> bool
211
-
212
- alias arg angle
213
-
214
- # Returns the number of bits of the value of `int`.
215
- #
216
- # "Number of bits" means the bit position of the highest bit which is different
217
- # from the sign bit (where the least significant bit has bit position 1). If
218
- # there is no such bit (zero or minus one), zero is returned.
219
- #
220
- # I.e. this method returns *ceil(log2(int < 0 ? -int : int+1))*.
221
- #
222
- # (-2**1000-1).bit_length #=> 1001
223
- # (-2**1000).bit_length #=> 1000
224
- # (-2**1000+1).bit_length #=> 1000
225
- # (-2**12-1).bit_length #=> 13
226
- # (-2**12).bit_length #=> 12
227
- # (-2**12+1).bit_length #=> 12
228
- # -0x101.bit_length #=> 9
229
- # -0x100.bit_length #=> 8
230
- # -0xff.bit_length #=> 8
231
- # -2.bit_length #=> 1
232
- # -1.bit_length #=> 0
233
- # 0.bit_length #=> 0
234
- # 1.bit_length #=> 1
235
- # 0xff.bit_length #=> 8
236
- # 0x100.bit_length #=> 9
237
- # (2**12-1).bit_length #=> 12
238
- # (2**12).bit_length #=> 13
239
- # (2**12+1).bit_length #=> 13
240
- # (2**1000-1).bit_length #=> 1000
241
- # (2**1000).bit_length #=> 1001
242
- # (2**1000+1).bit_length #=> 1001
243
- #
244
- # This method can be used to detect overflow in Array#pack as follows:
245
- #
246
- # if n.bit_length < 32
247
- # [n].pack("l") # no overflow
248
- # else
249
- # raise "overflow"
250
- # end
251
- #
252
- def bit_length: () -> Integer
253
-
254
- # Returns the smallest number greater than or equal to `int` with a precision of
255
- # `ndigits` decimal digits (default: 0).
256
- #
257
- # When the precision is negative, the returned value is an integer with at least
258
- # `ndigits.abs` trailing zeros.
259
- #
260
- # Returns `self` when `ndigits` is zero or positive.
261
- #
262
- # 1.ceil #=> 1
263
- # 1.ceil(2) #=> 1
264
- # 18.ceil(-1) #=> 20
265
- # (-18).ceil(-1) #=> -10
266
- #
267
- def ceil: () -> Integer
268
- | (int digits) -> (Integer | Float)
269
-
270
- # Returns a string containing the character represented by the `int`'s value
271
- # according to `encoding`.
272
- #
273
- # 65.chr #=> "A"
274
- # 230.chr #=> "\xE6"
275
- # 255.chr(Encoding::UTF_8) #=> "\u00FF"
276
- #
277
- def chr: (?Encoding | string) -> String
278
-
279
- def clone: (?freeze: bool) -> self
280
-
281
- # Returns an array with both a `numeric` and a `big` represented as Bignum
282
- # objects.
283
- #
284
- # This is achieved by converting `numeric` to a Bignum.
285
- #
286
- # A TypeError is raised if the `numeric` is not a Fixnum or Bignum type.
287
- #
288
- # (0x3FFFFFFFFFFFFFFF+1).coerce(42) #=> [42, 4611686018427387904]
289
- #
290
- def coerce: (Numeric) -> [Numeric, Numeric]
291
-
292
- def conj: () -> Integer
293
-
294
- def conjugate: () -> Integer
295
-
296
- # Returns 1.
297
- #
298
- def denominator: () -> Integer
299
-
300
- # Returns the digits of `int`'s place-value representation with radix `base`
301
- # (default: 10). The digits are returned as an array with the least significant
302
- # digit as the first array element.
303
- #
304
- # `base` must be greater than or equal to 2.
305
- #
306
- # 12345.digits #=> [5, 4, 3, 2, 1]
307
- # 12345.digits(7) #=> [4, 6, 6, 0, 5]
308
- # 12345.digits(100) #=> [45, 23, 1]
309
- #
310
- # -12345.digits(7) #=> Math::DomainError
311
- #
312
- def digits: (?int base) -> ::Array[Integer]
313
-
314
- # Performs integer division: returns the integer result of dividing `int` by
315
- # `numeric`.
316
- #
317
- def div: (Numeric) -> Integer
318
-
319
- # See Numeric#divmod.
320
- #
321
- def divmod: (Integer) -> [Integer, Integer]
322
- | (Float) -> [Float, Float]
323
- | (Numeric) -> [Numeric, Numeric]
324
-
325
- # Iterates the given block, passing in decreasing values from `int` down to and
326
- # including `limit`.
327
- #
328
- # If no block is given, an Enumerator is returned instead.
329
- #
330
- # 5.downto(1) { |n| print n, ".. " }
331
- # puts "Liftoff!"
332
- # #=> "5.. 4.. 3.. 2.. 1.. Liftoff!"
333
- #
334
- def downto: (Integer limit) { (Integer) -> void } -> Integer
335
- | (Integer limit) -> ::Enumerator[Integer, self]
336
-
337
- def dup: () -> self
338
-
339
- def eql?: (untyped) -> bool
340
-
341
- # Returns `true` if `int` is an even number.
342
- #
343
- def even?: () -> bool
344
-
345
- # Returns the floating point result of dividing `int` by `numeric`.
346
- #
347
- # 654321.fdiv(13731) #=> 47.652829364212366
348
- # 654321.fdiv(13731.24) #=> 47.65199646936475
349
- # -654321.fdiv(13731) #=> -47.652829364212366
350
- #
351
- def fdiv: (Numeric) -> Float
352
-
353
- def finite?: () -> bool
354
-
355
- # Returns the largest number less than or equal to `int` with a precision of
356
- # `ndigits` decimal digits (default: 0).
357
- #
358
- # When the precision is negative, the returned value is an integer with at least
359
- # `ndigits.abs` trailing zeros.
360
- #
361
- # Returns `self` when `ndigits` is zero or positive.
362
- #
363
- # 1.floor #=> 1
364
- # 1.floor(2) #=> 1
365
- # 18.floor(-1) #=> 10
366
- # (-18).floor(-1) #=> -20
367
- #
368
- def floor: () -> Integer
369
- | (int digits) -> (Integer | Float)
370
-
371
- # Returns the greatest common divisor of the two integers. The result is always
372
- # positive. 0.gcd(x) and x.gcd(0) return x.abs.
373
- #
374
- # 36.gcd(60) #=> 12
375
- # 2.gcd(2) #=> 2
376
- # 3.gcd(-7) #=> 1
377
- # ((1<<31)-1).gcd((1<<61)-1) #=> 1
378
- #
379
- def gcd: (Integer) -> Integer
380
-
381
- # Returns an array with the greatest common divisor and the least common
382
- # multiple of the two integers, [gcd, lcm].
383
- #
384
- # 36.gcdlcm(60) #=> [12, 180]
385
- # 2.gcdlcm(2) #=> [2, 2]
386
- # 3.gcdlcm(-7) #=> [1, 21]
387
- # ((1<<31)-1).gcdlcm((1<<61)-1) #=> [1, 4951760154835678088235319297]
388
- #
389
- def gcdlcm: (Integer) -> [ Integer, Integer ]
390
-
391
- def i: () -> Complex
392
-
393
- def imag: () -> Integer
394
-
395
- def imaginary: () -> Integer
396
-
397
- def infinite?: () -> Integer?
398
-
399
- alias inspect to_s
400
-
401
- # Since `int` is already an Integer, this always returns `true`.
402
- #
403
- def integer?: () -> true
404
-
405
- # Returns the least common multiple of the two integers. The result is always
406
- # positive. 0.lcm(x) and x.lcm(0) return zero.
407
- #
408
- # 36.lcm(60) #=> 180
409
- # 2.lcm(2) #=> 2
410
- # 3.lcm(-7) #=> 21
411
- # ((1<<31)-1).lcm((1<<61)-1) #=> 4951760154835678088235319297
412
- #
413
- def lcm: (Integer) -> Integer
414
-
415
- # Returns the absolute value of `int`.
416
- #
417
- # (-12345).abs #=> 12345
418
- # -12345.abs #=> 12345
419
- # 12345.abs #=> 12345
420
- #
421
- # Integer#magnitude is an alias for Integer#abs.
422
- #
423
- def magnitude: () -> Integer
424
-
425
- # Returns `int` modulo `other`.
426
- #
427
- # See Numeric#divmod for more information.
428
- #
429
- alias modulo `%`
430
-
431
- def negative?: () -> bool
432
-
433
- # Returns the successor of `int`, i.e. the Integer equal to `int+1`.
434
- #
435
- # 1.next #=> 2
436
- # (-1).next #=> 0
437
- # 1.succ #=> 2
438
- # (-1).succ #=> 0
439
- #
440
- def next: () -> Integer
441
-
442
- # Returns `true` if no bits of `int & mask` are 1.
443
- #
444
- def nobits?: (int mask) -> bool
445
-
446
- def nonzero?: () -> self?
447
-
448
- # Returns self.
449
- #
450
- def numerator: () -> Integer
451
-
452
- # Returns `true` if `int` is an odd number.
453
- #
454
- def odd?: () -> bool
455
-
456
- # Returns the `int` itself.
457
- #
458
- # 97.ord #=> 97
459
- #
460
- # This method is intended for compatibility to character literals in Ruby 1.9.
461
- #
462
- # For example, `?a.ord` returns 97 both in 1.8 and 1.9.
463
- #
464
- def ord: () -> Integer
465
-
466
- alias phase angle
467
-
468
- def polar: () -> [ Integer, Integer | Float ]
469
-
470
- def positive?: () -> bool
471
-
472
- # Returns (modular) exponentiation as:
473
- #
474
- # a.pow(b) #=> same as a**b
475
- # a.pow(b, m) #=> same as (a**b) % m, but avoids huge temporary values
476
- #
477
- def pow: (Integer other, ?Integer modulo) -> Integer
478
- | (Numeric numeric) -> Numeric
479
-
480
- # Returns the predecessor of `int`, i.e. the Integer equal to `int-1`.
481
- #
482
- # 1.pred #=> 0
483
- # (-1).pred #=> -2
484
- #
485
- def pred: () -> Integer
486
-
487
- def quo: (Integer) -> Rational
488
- | (Float) -> Float
489
- | (Rational) -> Rational
490
- | (Complex) -> Complex
491
- | (Numeric) -> Numeric
492
-
493
- # Returns the value as a rational. The optional argument `eps` is always
494
- # ignored.
495
- #
496
- def rationalize: (?Numeric eps) -> Rational
497
-
498
- def real: () -> self
499
-
500
- def real?: () -> true
501
-
502
- def rect: () -> [ Integer, Numeric ]
503
-
504
- alias rectangular rect
505
-
506
- # Returns the remainder after dividing `int` by `numeric`.
507
- #
508
- # `x.remainder(y)` means `x-y*(x/y).truncate`.
509
- #
510
- # 5.remainder(3) #=> 2
511
- # -5.remainder(3) #=> -2
512
- # 5.remainder(-3) #=> 2
513
- # -5.remainder(-3) #=> -2
514
- # 5.remainder(1.5) #=> 0.5
515
- #
516
- # See Numeric#divmod.
517
- #
518
- def remainder: (Integer) -> Integer
519
- | (Float) -> Float
520
- | (Rational) -> Rational
521
- | (Numeric) -> Numeric
522
-
523
- # Returns `int` rounded to the nearest value with a precision of `ndigits`
524
- # decimal digits (default: 0).
525
- #
526
- # When the precision is negative, the returned value is an integer with at least
527
- # `ndigits.abs` trailing zeros.
528
- #
529
- # Returns `self` when `ndigits` is zero or positive.
530
- #
531
- # 1.round #=> 1
532
- # 1.round(2) #=> 1
533
- # 15.round(-1) #=> 20
534
- # (-15).round(-1) #=> -20
535
- #
536
- # The optional `half` keyword argument is available similar to Float#round.
537
- #
538
- # 25.round(-1, half: :up) #=> 30
539
- # 25.round(-1, half: :down) #=> 20
540
- # 25.round(-1, half: :even) #=> 20
541
- # 35.round(-1, half: :up) #=> 40
542
- # 35.round(-1, half: :down) #=> 30
543
- # 35.round(-1, half: :even) #=> 40
544
- # (-25).round(-1, half: :up) #=> -30
545
- # (-25).round(-1, half: :down) #=> -20
546
- # (-25).round(-1, half: :even) #=> -20
547
- #
548
- def round: (?half: :up | :down | :even) -> Integer
549
- | (int digits, ?half: :up | :down | :even) -> (Integer | Float)
550
-
551
- # Returns the number of bytes in the machine representation of `int` (machine
552
- # dependent).
553
- #
554
- # 1.size #=> 8
555
- # -1.size #=> 8
556
- # 2147483647.size #=> 8
557
- # (256**10 - 1).size #=> 10
558
- # (256**20 - 1).size #=> 20
559
- # (256**40 - 1).size #=> 40
560
- #
561
- def size: () -> Integer
562
-
563
- def step: () { (Integer) -> void } -> void
564
- | (Numeric limit, ?Integer step) { (Integer) -> void } -> void
565
- | (Numeric limit, ?Numeric step) { (Numeric) -> void } -> void
566
- | (to: Numeric, ?by: Integer) { (Integer) -> void } -> void
567
- | (?to: Numeric, by: Numeric) { (Numeric) -> void } -> void
568
- | () -> Enumerator[Integer, bot]
569
- | (Numeric limit, ?Integer step) -> Enumerator[Integer, void]
570
- | (Numeric limit, ?Numeric step) -> Enumerator[Numeric, void]
571
- | (to: Numeric, ?by: Integer) -> Enumerator[Integer, void]
572
- | (?to: Numeric, by: Numeric) -> Enumerator[Numeric, void]
573
-
574
- # Returns the successor of `int`, i.e. the Integer equal to `int+1`.
575
- #
576
- # 1.next #=> 2
577
- # (-1).next #=> 0
578
- # 1.succ #=> 2
579
- # (-1).succ #=> 0
580
- #
581
- def succ: () -> Integer
582
-
583
- # Iterates the given block `int` times, passing in values from zero to `int -
584
- # 1`.
585
- #
586
- # If no block is given, an Enumerator is returned instead.
587
- #
588
- # 5.times {|i| print i, " " } #=> 0 1 2 3 4
589
- #
590
- def times: () { (Integer) -> void } -> self
591
- | () -> ::Enumerator[Integer, self]
592
-
593
- def to_c: () -> Complex
594
-
595
- # Converts `int` to a Float. If `int` doesn't fit in a Float, the result is
596
- # infinity.
597
- #
598
- def to_f: () -> Float
599
-
600
- # Since `int` is already an Integer, returns `self`.
601
- #
602
- # #to_int is an alias for #to_i.
603
- #
604
- def to_i: () -> Integer
605
-
606
- # Since `int` is already an Integer, returns `self`.
607
- #
608
- # #to_int is an alias for #to_i.
609
- #
610
- alias to_int to_i
611
-
612
- # Returns the value as a rational.
613
- #
614
- # 1.to_r #=> (1/1)
615
- # (1<<64).to_r #=> (18446744073709551616/1)
616
- #
617
- def to_r: () -> Rational
618
-
619
- # Returns a string containing the place-value representation of `int` with radix
620
- # `base` (between 2 and 36).
621
- #
622
- # 12345.to_s #=> "12345"
623
- # 12345.to_s(2) #=> "11000000111001"
624
- # 12345.to_s(8) #=> "30071"
625
- # 12345.to_s(10) #=> "12345"
626
- # 12345.to_s(16) #=> "3039"
627
- # 12345.to_s(36) #=> "9ix"
628
- # 78546939656932.to_s(36) #=> "rubyrules"
629
- #
630
- def to_s: () -> String
631
- | (2) -> String
632
- | (3) -> String
633
- | (4) -> String
634
- | (5) -> String
635
- | (6) -> String
636
- | (7) -> String
637
- | (8) -> String
638
- | (9) -> String
639
- | (10) -> String
640
- | (11) -> String
641
- | (12) -> String
642
- | (13) -> String
643
- | (14) -> String
644
- | (15) -> String
645
- | (16) -> String
646
- | (17) -> String
647
- | (18) -> String
648
- | (19) -> String
649
- | (20) -> String
650
- | (21) -> String
651
- | (22) -> String
652
- | (23) -> String
653
- | (24) -> String
654
- | (25) -> String
655
- | (26) -> String
656
- | (27) -> String
657
- | (28) -> String
658
- | (29) -> String
659
- | (30) -> String
660
- | (31) -> String
661
- | (32) -> String
662
- | (33) -> String
663
- | (34) -> String
664
- | (35) -> String
665
- | (36) -> String
666
- | (int base) -> String
667
-
668
- # Returns `int` truncated (toward zero) to a precision of `ndigits` decimal
669
- # digits (default: 0).
670
- #
671
- # When the precision is negative, the returned value is an integer with at least
672
- # `ndigits.abs` trailing zeros.
673
- #
674
- # Returns `self` when `ndigits` is zero or positive.
675
- #
676
- # 1.truncate #=> 1
677
- # 1.truncate(2) #=> 1
678
- # 18.truncate(-1) #=> 10
679
- # (-18).truncate(-1) #=> -10
680
- #
681
- def truncate: () -> Integer
682
- | (int ndigits) -> Integer
683
-
684
- # Iterates the given block, passing in integer values from `int` up to and
685
- # including `limit`.
686
- #
687
- # If no block is given, an Enumerator is returned instead.
688
- #
689
- # 5.upto(10) {|i| print i, " " } #=> 5 6 7 8 9 10
690
- #
691
- def upto: (Integer limit) { (Integer) -> void } -> Integer
692
- | (Integer limit) -> ::Enumerator[Integer, self]
693
-
694
- def zero?: () -> bool
695
-
696
- # Bitwise OR.
697
- #
698
- def |: (Integer) -> Integer
699
-
700
- # One's complement: returns a number where each bit is flipped.
701
- #
702
- # Inverts the bits in an Integer. As integers are conceptually of infinite
703
- # length, the result acts as if it had an infinite number of one bits to the
704
- # left. In hex representations, this is displayed as two periods to the left of
705
- # the digits.
706
- #
707
- # sprintf("%X", ~0x1122334455) #=> "..FEEDDCCBBAA"
708
- #
709
- def ~: () -> Integer
710
- end