rbs 3.10.4 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +14 -14
  3. data/.github/workflows/bundle-update.yml +60 -0
  4. data/.github/workflows/c-check.yml +7 -5
  5. data/.github/workflows/comments.yml +2 -2
  6. data/.github/workflows/dependabot.yml +2 -2
  7. data/.github/workflows/ruby.yml +16 -26
  8. data/.github/workflows/rust.yml +95 -0
  9. data/.github/workflows/typecheck.yml +1 -1
  10. data/.github/workflows/windows.yml +2 -2
  11. data/.rubocop.yml +2 -2
  12. data/.vscode/extensions.json +5 -0
  13. data/.vscode/settings.json +19 -0
  14. data/CHANGELOG.md +202 -2
  15. data/Rakefile +9 -23
  16. data/Steepfile +2 -0
  17. data/config.yml +457 -13
  18. data/core/array.rbs +218 -188
  19. data/core/basic_object.rbs +9 -8
  20. data/core/binding.rbs +0 -2
  21. data/core/builtin.rbs +2 -2
  22. data/core/class.rbs +6 -5
  23. data/core/comparable.rbs +45 -31
  24. data/core/complex.rbs +66 -55
  25. data/core/dir.rbs +57 -45
  26. data/core/encoding.rbs +6 -6
  27. data/core/enumerable.rbs +105 -91
  28. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  29. data/core/enumerator.rbs +24 -3
  30. data/core/errno.rbs +3 -2
  31. data/core/errors.rbs +31 -29
  32. data/core/exception.rbs +12 -12
  33. data/core/fiber.rbs +47 -36
  34. data/core/file.rbs +242 -169
  35. data/core/file_test.rbs +2 -2
  36. data/core/float.rbs +42 -68
  37. data/core/gc.rbs +78 -70
  38. data/core/hash.rbs +70 -60
  39. data/core/integer.rbs +32 -75
  40. data/core/io/buffer.rbs +36 -36
  41. data/core/io/wait.rbs +7 -7
  42. data/core/io.rbs +192 -146
  43. data/core/kernel.rbs +198 -147
  44. data/core/marshal.rbs +3 -3
  45. data/core/match_data.rbs +14 -12
  46. data/core/math.rbs +69 -67
  47. data/core/method.rbs +6 -8
  48. data/core/module.rbs +148 -88
  49. data/core/nil_class.rbs +4 -3
  50. data/core/numeric.rbs +53 -50
  51. data/core/object.rbs +6 -8
  52. data/core/object_space.rbs +11 -10
  53. data/core/pathname.rbs +131 -81
  54. data/core/proc.rbs +65 -34
  55. data/core/process.rbs +221 -201
  56. data/core/ractor.rbs +15 -11
  57. data/core/random.rbs +21 -3
  58. data/core/range.rbs +152 -49
  59. data/core/rational.rbs +5 -56
  60. data/core/rbs/unnamed/argf.rbs +58 -51
  61. data/core/rbs/unnamed/env_class.rbs +18 -13
  62. data/core/rbs/unnamed/main_class.rbs +123 -0
  63. data/core/rbs/unnamed/random.rbs +7 -116
  64. data/core/regexp.rbs +236 -197
  65. data/core/ruby.rbs +1 -1
  66. data/core/ruby_vm.rbs +32 -30
  67. data/core/rubygems/config_file.rbs +5 -5
  68. data/core/rubygems/errors.rbs +1 -1
  69. data/core/rubygems/requirement.rbs +5 -5
  70. data/core/rubygems/rubygems.rbs +5 -3
  71. data/core/set.rbs +17 -16
  72. data/core/signal.rbs +2 -2
  73. data/core/string.rbs +318 -298
  74. data/core/struct.rbs +26 -25
  75. data/core/symbol.rbs +25 -24
  76. data/core/thread.rbs +40 -41
  77. data/core/time.rbs +47 -42
  78. data/core/trace_point.rbs +34 -31
  79. data/core/true_class.rbs +2 -2
  80. data/core/unbound_method.rbs +10 -10
  81. data/core/warning.rbs +7 -7
  82. data/docs/collection.md +1 -1
  83. data/docs/config.md +171 -0
  84. data/docs/inline.md +576 -0
  85. data/docs/syntax.md +46 -16
  86. data/docs/type_fingerprint.md +21 -0
  87. data/exe/rbs +1 -1
  88. data/ext/rbs_extension/ast_translation.c +595 -98
  89. data/ext/rbs_extension/class_constants.c +30 -0
  90. data/ext/rbs_extension/class_constants.h +15 -0
  91. data/ext/rbs_extension/legacy_location.c +30 -53
  92. data/ext/rbs_extension/legacy_location.h +37 -0
  93. data/ext/rbs_extension/main.c +125 -24
  94. data/include/rbs/ast.h +485 -150
  95. data/include/rbs/lexer.h +11 -4
  96. data/include/rbs/location.h +25 -44
  97. data/include/rbs/parser.h +20 -2
  98. data/include/rbs/util/rbs_constant_pool.h +0 -3
  99. data/include/rbs.h +8 -0
  100. data/lib/rbs/ast/annotation.rb +1 -1
  101. data/lib/rbs/ast/comment.rb +1 -1
  102. data/lib/rbs/ast/declarations.rb +10 -10
  103. data/lib/rbs/ast/members.rb +14 -14
  104. data/lib/rbs/ast/ruby/annotations.rb +409 -0
  105. data/lib/rbs/ast/ruby/comment_block.rb +245 -0
  106. data/lib/rbs/ast/ruby/declarations.rb +281 -0
  107. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
  108. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  109. data/lib/rbs/ast/ruby/members.rb +723 -0
  110. data/lib/rbs/ast/type_param.rb +24 -4
  111. data/lib/rbs/buffer.rb +105 -20
  112. data/lib/rbs/cli/diff.rb +16 -15
  113. data/lib/rbs/cli/validate.rb +62 -125
  114. data/lib/rbs/cli.rb +55 -23
  115. data/lib/rbs/collection/config/lockfile_generator.rb +8 -4
  116. data/lib/rbs/collection/sources/git.rb +1 -0
  117. data/lib/rbs/collection.rb +0 -1
  118. data/lib/rbs/definition.rb +6 -1
  119. data/lib/rbs/definition_builder/ancestor_builder.rb +119 -63
  120. data/lib/rbs/definition_builder/method_builder.rb +65 -30
  121. data/lib/rbs/definition_builder.rb +177 -20
  122. data/lib/rbs/diff.rb +7 -1
  123. data/lib/rbs/environment/class_entry.rb +69 -0
  124. data/lib/rbs/environment/module_entry.rb +66 -0
  125. data/lib/rbs/environment.rb +338 -155
  126. data/lib/rbs/environment_loader.rb +2 -2
  127. data/lib/rbs/errors.rb +30 -20
  128. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  129. data/lib/rbs/inline_parser.rb +542 -0
  130. data/lib/rbs/location_aux.rb +36 -4
  131. data/lib/rbs/locator.rb +5 -1
  132. data/lib/rbs/method_type.rb +5 -3
  133. data/lib/rbs/namespace.rb +0 -7
  134. data/lib/rbs/parser_aux.rb +31 -8
  135. data/lib/rbs/prototype/helpers.rb +57 -0
  136. data/lib/rbs/prototype/rb.rb +3 -28
  137. data/lib/rbs/prototype/rbi.rb +3 -20
  138. data/lib/rbs/prototype/runtime.rb +10 -2
  139. data/lib/rbs/resolver/type_name_resolver.rb +0 -8
  140. data/lib/rbs/source.rb +99 -0
  141. data/lib/rbs/subtractor.rb +4 -3
  142. data/lib/rbs/test/type_check.rb +5 -2
  143. data/lib/rbs/type_name.rb +1 -8
  144. data/lib/rbs/types.rb +88 -78
  145. data/lib/rbs/unit_test/convertibles.rb +1 -0
  146. data/lib/rbs/unit_test/type_assertions.rb +35 -8
  147. data/lib/rbs/validator.rb +2 -2
  148. data/lib/rbs/version.rb +1 -1
  149. data/lib/rbs.rb +12 -1
  150. data/rbs.gemspec +3 -2
  151. data/rust/.gitignore +1 -0
  152. data/rust/Cargo.lock +378 -0
  153. data/rust/Cargo.toml +7 -0
  154. data/rust/ruby-rbs/Cargo.toml +22 -0
  155. data/rust/ruby-rbs/build.rs +764 -0
  156. data/rust/ruby-rbs/examples/locations.rs +60 -0
  157. data/rust/ruby-rbs/src/lib.rs +1 -0
  158. data/rust/ruby-rbs/src/node/mod.rs +742 -0
  159. data/rust/ruby-rbs/tests/sanity.rs +47 -0
  160. data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
  161. data/rust/ruby-rbs-sys/Cargo.toml +23 -0
  162. data/rust/ruby-rbs-sys/build.rs +204 -0
  163. data/rust/ruby-rbs-sys/src/lib.rs +50 -0
  164. data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
  165. data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
  166. data/rust/ruby-rbs-sys/wrapper.h +1 -0
  167. data/schema/typeParam.json +17 -1
  168. data/sig/ancestor_builder.rbs +1 -1
  169. data/sig/ast/ruby/annotations.rbs +421 -0
  170. data/sig/ast/ruby/comment_block.rbs +127 -0
  171. data/sig/ast/ruby/declarations.rbs +158 -0
  172. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  173. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  174. data/sig/ast/ruby/members.rbs +178 -0
  175. data/sig/buffer.rbs +63 -5
  176. data/sig/cli/diff.rbs +5 -11
  177. data/sig/cli/validate.rbs +12 -8
  178. data/sig/cli.rbs +18 -18
  179. data/sig/definition.rbs +6 -0
  180. data/sig/definition_builder.rbs +3 -1
  181. data/sig/environment/class_entry.rbs +50 -0
  182. data/sig/environment/module_entry.rbs +50 -0
  183. data/sig/environment.rbs +37 -81
  184. data/sig/errors.rbs +26 -20
  185. data/sig/inline_parser/comment_association.rbs +71 -0
  186. data/sig/inline_parser.rbs +124 -0
  187. data/sig/location.rbs +32 -7
  188. data/sig/locator.rbs +0 -2
  189. data/sig/method_builder.rbs +9 -4
  190. data/sig/namespace.rbs +0 -5
  191. data/sig/parser.rbs +47 -13
  192. data/sig/prototype/helpers.rbs +2 -0
  193. data/sig/resolver/type_name_resolver.rbs +0 -3
  194. data/sig/source.rbs +48 -0
  195. data/sig/type_param.rbs +13 -8
  196. data/sig/typename.rbs +0 -5
  197. data/sig/types.rbs +6 -7
  198. data/sig/unit_test/spy.rbs +0 -8
  199. data/sig/unit_test/type_assertions.rbs +11 -0
  200. data/src/ast.c +491 -143
  201. data/src/lexer.c +1552 -1314
  202. data/src/lexer.re +7 -0
  203. data/src/lexstate.c +8 -1
  204. data/src/location.c +8 -48
  205. data/src/parser.c +1107 -409
  206. data/src/util/rbs_constant_pool.c +0 -4
  207. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -16
  208. data/stdlib/cgi-escape/0/escape.rbs +4 -4
  209. data/stdlib/coverage/0/coverage.rbs +4 -3
  210. data/stdlib/date/0/date.rbs +33 -28
  211. data/stdlib/date/0/date_time.rbs +24 -23
  212. data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
  213. data/stdlib/digest/0/digest.rbs +110 -0
  214. data/stdlib/erb/0/erb.rbs +64 -53
  215. data/stdlib/etc/0/etc.rbs +55 -50
  216. data/stdlib/fileutils/0/fileutils.rbs +140 -126
  217. data/stdlib/forwardable/0/forwardable.rbs +10 -10
  218. data/stdlib/io-console/0/io-console.rbs +2 -2
  219. data/stdlib/json/0/json.rbs +158 -131
  220. data/stdlib/monitor/0/monitor.rbs +3 -3
  221. data/stdlib/net-http/0/net-http.rbs +159 -134
  222. data/stdlib/objspace/0/objspace.rbs +8 -30
  223. data/stdlib/open-uri/0/open-uri.rbs +8 -8
  224. data/stdlib/open3/0/open3.rbs +469 -10
  225. data/stdlib/openssl/0/openssl.rbs +144 -129
  226. data/stdlib/optparse/0/optparse.rbs +23 -14
  227. data/stdlib/pathname/0/pathname.rbs +2 -2
  228. data/stdlib/pp/0/pp.rbs +9 -8
  229. data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
  230. data/stdlib/pstore/0/pstore.rbs +35 -30
  231. data/stdlib/psych/0/psych.rbs +62 -9
  232. data/stdlib/psych/0/store.rbs +2 -4
  233. data/stdlib/pty/0/pty.rbs +9 -6
  234. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  235. data/stdlib/rdoc/0/code_object.rbs +2 -1
  236. data/stdlib/rdoc/0/parser.rbs +1 -1
  237. data/stdlib/rdoc/0/store.rbs +1 -1
  238. data/stdlib/ripper/0/ripper.rbs +20 -17
  239. data/stdlib/securerandom/0/manifest.yaml +2 -0
  240. data/stdlib/securerandom/0/securerandom.rbs +7 -20
  241. data/stdlib/shellwords/0/shellwords.rbs +2 -2
  242. data/stdlib/socket/0/addrinfo.rbs +9 -9
  243. data/stdlib/socket/0/basic_socket.rbs +3 -3
  244. data/stdlib/socket/0/ip_socket.rbs +10 -8
  245. data/stdlib/socket/0/socket.rbs +10 -9
  246. data/stdlib/socket/0/tcp_server.rbs +1 -1
  247. data/stdlib/socket/0/tcp_socket.rbs +1 -1
  248. data/stdlib/socket/0/udp_socket.rbs +1 -1
  249. data/stdlib/socket/0/unix_server.rbs +1 -1
  250. data/stdlib/stringio/0/stringio.rbs +55 -54
  251. data/stdlib/strscan/0/string_scanner.rbs +46 -44
  252. data/stdlib/tempfile/0/tempfile.rbs +24 -20
  253. data/stdlib/time/0/time.rbs +7 -5
  254. data/stdlib/tsort/0/tsort.rbs +7 -6
  255. data/stdlib/uri/0/common.rbs +31 -18
  256. data/stdlib/uri/0/file.rbs +2 -2
  257. data/stdlib/uri/0/generic.rbs +9 -2
  258. data/stdlib/uri/0/http.rbs +2 -2
  259. data/stdlib/uri/0/ldap.rbs +2 -2
  260. data/stdlib/uri/0/mailto.rbs +3 -3
  261. data/stdlib/uri/0/rfc2396_parser.rbs +6 -5
  262. data/stdlib/zlib/0/deflate.rbs +4 -3
  263. data/stdlib/zlib/0/gzip_reader.rbs +6 -6
  264. data/stdlib/zlib/0/gzip_writer.rbs +14 -12
  265. data/stdlib/zlib/0/inflate.rbs +1 -1
  266. data/stdlib/zlib/0/need_dict.rbs +1 -1
  267. metadata +66 -3
@@ -17,7 +17,8 @@
17
17
  # * Do not have namespace "pollution" from the many methods provided in class
18
18
  # Object and its included module Kernel.
19
19
  # * Do not have definitions of common classes, and so references to such
20
- # common classes must be fully qualified (`::String`, not `String`).
20
+ # common classes must be fully qualified (<code>::String</code>, not
21
+ # `String`).
21
22
  #
22
23
  # A variety of strategies can be used to provide useful portions of the Standard
23
24
  # Library in subclasses of `BasicObject`:
@@ -92,8 +93,8 @@ class BasicObject
92
93
  # classes to provide class-specific meaning.
93
94
  #
94
95
  # Unlike #==, the #equal? method should never be overridden by subclasses as it
95
- # is used to determine object identity (that is, `a.equal?(b)` if and only if
96
- # `a` is the same object as `b`):
96
+ # is used to determine object identity (that is, <code>a.equal?(b)</code> if and
97
+ # only if `a` is the same object as `b`):
97
98
  #
98
99
  # obj = "a"
99
100
  # other = obj.dup
@@ -174,8 +175,8 @@ class BasicObject
174
175
  # classes to provide class-specific meaning.
175
176
  #
176
177
  # Unlike #==, the #equal? method should never be overridden by subclasses as it
177
- # is used to determine object identity (that is, `a.equal?(b)` if and only if
178
- # `a` is the same object as `b`):
178
+ # is used to determine object identity (that is, <code>a.equal?(b)</code> if and
179
+ # only if `a` is the same object as `b`):
179
180
  #
180
181
  # obj = "a"
181
182
  # other = obj.dup
@@ -315,7 +316,7 @@ class BasicObject
315
316
  # def Chatty.three() end
316
317
  # end
317
318
  #
318
- # *produces:*
319
+ # <em>produces:</em>
319
320
  #
320
321
  # Adding singleton_method_added
321
322
  # Adding one
@@ -343,7 +344,7 @@ class BasicObject
343
344
  # end
344
345
  # end
345
346
  #
346
- # *produces:*
347
+ # <em>produces:</em>
347
348
  #
348
349
  # Removing three
349
350
  # Removing one
@@ -367,7 +368,7 @@ class BasicObject
367
368
  # end
368
369
  # end
369
370
  #
370
- # *produces:*
371
+ # <em>produces:</em>
371
372
  #
372
373
  # Undefining one
373
374
  #
data/core/binding.rbs CHANGED
@@ -32,8 +32,6 @@
32
32
  class Binding
33
33
  def clone: () -> self
34
34
 
35
- def dup: () -> self
36
-
37
35
  # <!--
38
36
  # rdoc-file=proc.c
39
37
  # - binding.eval(string [, filename [,lineno]]) -> obj
data/core/builtin.rbs CHANGED
@@ -9,7 +9,7 @@ end
9
9
  # A type that's convertible to a `Rational`.
10
10
  #
11
11
  interface _ToR
12
- # Convert `self` to a `Complex`.
12
+ # Convert `self` to a `Rational`.
13
13
  #
14
14
  def to_r: () -> Rational
15
15
  end
@@ -58,7 +58,7 @@ end
58
58
  #
59
59
  # Implicit `.to_str` conversions are usable all over Ruby's stdlib, such as `Kernel#abort`,
60
60
  # `String#+`, and `Object#send`. Virtually anywhere that accepts a `String` will also accept
61
- # something that defines `.to_Str`.
61
+ # something that defines `.to_str`.
62
62
  #
63
63
  # Types that define `.to_str` are also usable wherever paths are expected (See the `path` type
64
64
  # alias).
data/core/class.rbs CHANGED
@@ -10,8 +10,9 @@
10
10
  # When a new class is created, an object of type Class is initialized and
11
11
  # assigned to a global constant (Name in this case).
12
12
  #
13
- # When `Name.new` is called to create a new object, the #new method in Class is
14
- # run by default. This can be demonstrated by overriding #new in Class:
13
+ # When <code>Name.new</code> is called to create a new object, the #new method
14
+ # in Class is run by default. This can be demonstrated by overriding #new in
15
+ # Class:
15
16
  #
16
17
  # class Class
17
18
  # alias old_new new
@@ -26,7 +27,7 @@
26
27
  #
27
28
  # n = Name.new
28
29
  #
29
- # *produces:*
30
+ # <em>produces:</em>
30
31
  #
31
32
  # Creating a new Name
32
33
  #
@@ -144,7 +145,7 @@ class Class < Module
144
145
  # class Baz < Bar
145
146
  # end
146
147
  #
147
- # *produces:*
148
+ # <em>produces:</em>
148
149
  #
149
150
  # New subclass: Bar
150
151
  # New subclass: Baz
@@ -157,7 +158,7 @@ class Class < Module
157
158
  # -->
158
159
  # Calls #allocate to create a new object of *class*'s class, then invokes that
159
160
  # object's #initialize method, passing it *args*. This is the method that ends
160
- # up getting called whenever an object is constructed using `.new`.
161
+ # up getting called whenever an object is constructed using <code>.new</code>.
161
162
  #
162
163
  def new: () -> untyped
163
164
 
data/core/comparable.rbs CHANGED
@@ -1,12 +1,13 @@
1
1
  # <!-- rdoc-file=compar.c -->
2
2
  # The Comparable mixin is used by classes whose objects may be ordered. The
3
- # class must define the `<=>` operator, which compares the receiver against
4
- # another object, returning a value less than 0, returning 0, or returning a
5
- # value greater than 0, depending on whether the receiver is less than, equal
6
- # to, or greater than the other object. If the other object is not comparable
7
- # then the `<=>` operator should return `nil`. Comparable uses `<=>` to
8
- # implement the conventional comparison operators (`<`, `<=`, `==`, `>=`, and
9
- # `>`) and the method `between?`.
3
+ # class must define the <code><=></code> operator, which compares the receiver
4
+ # against another object, returning a value less than 0, returning 0, or
5
+ # returning a value greater than 0, depending on whether the receiver is less
6
+ # than, equal to, or greater than the other object. If the other object is not
7
+ # comparable then the <code><=></code> operator should return `nil`. Comparable
8
+ # uses <code><=></code> to implement the conventional comparison operators
9
+ # (<code><</code>, <code><=</code>, <code>==</code>, <code>>=</code>, and
10
+ # <code>></code>) and the method <code>between?</code>.
10
11
  #
11
12
  # class StringSorter
12
13
  # include Comparable
@@ -38,7 +39,8 @@
38
39
  #
39
40
  # ## What's Here
40
41
  #
41
- # Module Comparable provides these methods, all of which use method `#<=>`:
42
+ # Module Comparable provides these methods, all of which use method
43
+ # <code>#<=></code>:
42
44
  #
43
45
  # * #<: Returns whether `self` is less than the given object.
44
46
  # * #<=: Returns whether `self` is less than or equal to the given object.
@@ -46,10 +48,11 @@
46
48
  # * #>: Returns whether `self` is greater than the given object.
47
49
  # * #>=: Returns whether `self` is greater than or equal to the given object.
48
50
  # * #between?: Returns `true` if `self` is between two given objects.
49
- # * #clamp: For given objects `min` and `max`, or range `(min..max)`, returns:
51
+ # * #clamp: For given objects `min` and `max`, or range
52
+ # <code>(min..max)</code>, returns:
50
53
  #
51
- # * `min` if `(self <=> min) < 0`.
52
- # * `max` if `(self <=> max) > 0`.
54
+ # * `min` if <code>(self <=> min) < 0</code>.
55
+ # * `max` if <code>(self <=> max) > 0</code>.
53
56
  # * `self` otherwise.
54
57
  #
55
58
  module Comparable : _WithSpaceshipOperator
@@ -57,8 +60,8 @@ module Comparable : _WithSpaceshipOperator
57
60
  # rdoc-file=compar.c
58
61
  # - self < other -> true or false
59
62
  # -->
60
- # Returns whether `self` is "less than" `other`; equivalent to `(self <=> other)
61
- # < 0`:
63
+ # Returns whether `self` is "less than" `other`; equivalent to <code>(self <=>
64
+ # other) < 0</code>:
62
65
  #
63
66
  # 'foo' < 'foo' # => false
64
67
  # 'foo' < 'food' # => true
@@ -70,7 +73,7 @@ module Comparable : _WithSpaceshipOperator
70
73
  # - self <= other -> true or false
71
74
  # -->
72
75
  # Returns whether `self` is "less than or equal to" `other`; equivalent to
73
- # `(self <=> other) <= 0`:
76
+ # <code>(self <=> other) <= 0</code>:
74
77
  #
75
78
  # 'foo' <= 'foo' # => true
76
79
  # 'foo' <= 'food' # => true
@@ -82,8 +85,9 @@ module Comparable : _WithSpaceshipOperator
82
85
  # rdoc-file=compar.c
83
86
  # - obj == other -> true or false
84
87
  # -->
85
- # Compares two objects based on the receiver's `<=>` method, returning true if
86
- # it returns 0. Also returns true if *obj* and *other* are the same object.
88
+ # Compares two objects based on the receiver's <code><=></code> method,
89
+ # returning true if it returns 0. Also returns true if *obj* and *other* are the
90
+ # same object.
87
91
  #
88
92
  def ==: (untyped other) -> bool
89
93
 
@@ -91,8 +95,8 @@ module Comparable : _WithSpaceshipOperator
91
95
  # rdoc-file=compar.c
92
96
  # - obj > other -> true or false
93
97
  # -->
94
- # Compares two objects based on the receiver's `<=>` method, returning true if
95
- # it returns a value greater than 0.
98
+ # Compares two objects based on the receiver's <code><=></code> method,
99
+ # returning true if it returns a value greater than 0.
96
100
  #
97
101
  def >: (untyped other) -> bool
98
102
 
@@ -100,8 +104,8 @@ module Comparable : _WithSpaceshipOperator
100
104
  # rdoc-file=compar.c
101
105
  # - obj >= other -> true or false
102
106
  # -->
103
- # Compares two objects based on the receiver's `<=>` method, returning true if
104
- # it returns a value greater than or equal to 0.
107
+ # Compares two objects based on the receiver's <code><=></code> method,
108
+ # returning true if it returns a value greater than or equal to 0.
105
109
  #
106
110
  def >=: (untyped other) -> bool
107
111
 
@@ -109,8 +113,8 @@ module Comparable : _WithSpaceshipOperator
109
113
  # rdoc-file=compar.c
110
114
  # - obj.between?(min, max) -> true or false
111
115
  # -->
112
- # Returns `false` if *obj* `<=>` *min* is less than zero or if *obj* `<=>` *max*
113
- # is greater than zero, `true` otherwise.
116
+ # Returns `false` if *obj* <code><=></code> *min* is less than zero or if *obj*
117
+ # <code><=></code> *max* is greater than zero, `true` otherwise.
114
118
  #
115
119
  # 3.between?(1, 5) #=> true
116
120
  # 6.between?(1, 5) #=> false
@@ -124,8 +128,9 @@ module Comparable : _WithSpaceshipOperator
124
128
  # - obj.clamp(min, max) -> obj
125
129
  # - obj.clamp(range) -> obj
126
130
  # -->
127
- # In `(min, max)` form, returns *min* if *obj* `<=>` *min* is less than zero,
128
- # *max* if *obj* `<=>` *max* is greater than zero, and *obj* otherwise.
131
+ # In <code>(min, max)</code> form, returns *min* if *obj* <code><=></code> *min*
132
+ # is less than zero, *max* if *obj* <code><=></code> *max* is greater than zero,
133
+ # and *obj* otherwise.
129
134
  #
130
135
  # 12.clamp(0, 100) #=> 12
131
136
  # 523.clamp(0, 100) #=> 100
@@ -140,9 +145,10 @@ module Comparable : _WithSpaceshipOperator
140
145
  # -20.clamp(0, nil) #=> 0
141
146
  # 523.clamp(nil, 100) #=> 100
142
147
  #
143
- # In `(range)` form, returns *range.begin* if *obj* `<=>` *range.begin* is less
144
- # than zero, *range.end* if *obj* `<=>` *range.end* is greater than zero, and
145
- # *obj* otherwise.
148
+ # In <code>(range)</code> form, returns <em>range.begin</em> if *obj*
149
+ # <code><=></code> <em>range.begin</em> is less than zero, <em>range.end</em> if
150
+ # *obj* <code><=></code> <em>range.end</em> is greater than zero, and *obj*
151
+ # otherwise.
146
152
  #
147
153
  # 12.clamp(0..100) #=> 12
148
154
  # 523.clamp(0..100) #=> 100
@@ -151,13 +157,13 @@ module Comparable : _WithSpaceshipOperator
151
157
  # 'd'.clamp('a'..'f') #=> 'd'
152
158
  # 'z'.clamp('a'..'f') #=> 'f'
153
159
  #
154
- # If *range.begin* is `nil`, it is considered smaller than *obj*, and if
155
- # *range.end* is `nil`, it is considered greater than *obj*.
160
+ # If <em>range.begin</em> is `nil`, it is considered smaller than *obj*, and if
161
+ # <em>range.end</em> is `nil`, it is considered greater than *obj*.
156
162
  #
157
163
  # -20.clamp(0..) #=> 0
158
164
  # 523.clamp(..100) #=> 100
159
165
  #
160
- # When *range.end* is excluded and not `nil`, an exception is raised.
166
+ # When <em>range.end</em> is excluded and not `nil`, an exception is raised.
161
167
  #
162
168
  # 100.clamp(0...100) # ArgumentError
163
169
  #
@@ -174,5 +180,13 @@ interface Comparable::_WithSpaceshipOperator
174
180
  # If `other` is less than `self`, it returns a positive Integer.
175
181
  # If no comparison is defined with `other` and `self`, it returns `nil`.
176
182
  #
177
- def <=>: (untyped other) -> Integer?
183
+ def <=>: (untyped other) -> Comparable::_CompareToZero?
184
+ end
185
+
186
+ # This interface indicates a type is comparable against zero.
187
+ #
188
+ interface Comparable::_CompareToZero
189
+ def <: (0) -> boolish
190
+
191
+ def >: (0) -> boolish
178
192
  end
data/core/complex.rbs CHANGED
@@ -79,17 +79,19 @@
79
79
  # * #arg (and its aliases #angle and #phase): Returns the argument (angle) for
80
80
  # `self` in radians.
81
81
  # * #denominator: Returns the denominator of `self`.
82
- # * #finite?: Returns whether both `self.real` and `self.image` are finite.
82
+ # * #finite?: Returns whether both <code>self.real</code> and
83
+ # <code>self.image</code> are finite.
83
84
  # * #hash: Returns the integer hash value for `self`.
84
85
  # * #imag (and its alias #imaginary): Returns the imaginary value for `self`.
85
- # * #infinite?: Returns whether `self.real` or `self.image` is infinite.
86
+ # * #infinite?: Returns whether <code>self.real</code> or
87
+ # <code>self.image</code> is infinite.
86
88
  # * #numerator: Returns the numerator of `self`.
87
- # * #polar: Returns the array `[self.abs, self.arg]`.
89
+ # * #polar: Returns the array <code>[self.abs, self.arg]</code>.
88
90
  # * #inspect: Returns a string representation of `self`.
89
91
  # * #real: Returns the real value for `self`.
90
92
  # * #real?: Returns `false`; for compatibility with Numeric#real?.
91
- # * #rect (and its alias #rectangular): Returns the array `[self.real,
92
- # self.imag]`.
93
+ # * #rect (and its alias #rectangular): Returns the array <code>[self.real,
94
+ # self.imag]</code>.
93
95
  #
94
96
  # ### Comparing
95
97
  #
@@ -100,12 +102,15 @@
100
102
  # ### Converting
101
103
  #
102
104
  # * #rationalize: Returns a Rational object whose value is exactly or
103
- # approximately equivalent to that of `self.real`.
105
+ # approximately equivalent to that of <code>self.real</code>.
104
106
  # * #to_c: Returns `self`.
105
107
  # * #to_d: Returns the value as a BigDecimal object.
106
- # * #to_f: Returns the value of `self.real` as a Float, if possible.
107
- # * #to_i: Returns the value of `self.real` as an Integer, if possible.
108
- # * #to_r: Returns the value of `self.real` as a Rational, if possible.
108
+ # * #to_f: Returns the value of <code>self.real</code> as a Float, if
109
+ # possible.
110
+ # * #to_i: Returns the value of <code>self.real</code> as an Integer, if
111
+ # possible.
112
+ # * #to_r: Returns the value of <code>self.real</code> as a Rational, if
113
+ # possible.
109
114
  # * #to_s: Returns a string representation of `self`.
110
115
  #
111
116
  # ### Performing Complex Arithmetic
@@ -118,7 +123,8 @@
118
123
  # * #/: Returns the quotient of `self` and the given numeric.
119
124
  # * #abs2: Returns square of the absolute value (magnitude) for `self`.
120
125
  # * #conj (and its alias #conjugate): Returns the conjugate of `self`.
121
- # * #fdiv: Returns `Complex.rect(self.real/numeric, self.imag/numeric)`.
126
+ # * #fdiv: Returns <code>Complex.rect(self.real/numeric,
127
+ # self.imag/numeric)</code>.
122
128
  #
123
129
  # ### Working with JSON
124
130
  #
@@ -232,8 +238,6 @@ class Complex < Numeric
232
238
  #
233
239
  def +: (Numeric) -> Complex
234
240
 
235
- def +@: () -> Complex
236
-
237
241
  # <!--
238
242
  # rdoc-file=complex.c
239
243
  # - self - other -> complex
@@ -285,10 +289,11 @@ class Complex < Numeric
285
289
  #
286
290
  # Returns:
287
291
  #
288
- # * `self.real <=> other.real` if both of the following are true:
292
+ # * <code>self.real <=> other.real</code> if both of the following are true:
289
293
  #
290
- # * `self.imag == 0`.
291
- # * `other.imag == 0` (always true if `other` is numeric but not complex).
294
+ # * <code>self.imag == 0</code>.
295
+ # * <code>other.imag == 0</code> (always true if `other` is numeric but
296
+ # not complex).
292
297
  #
293
298
  # * `nil` otherwise.
294
299
  #
@@ -310,7 +315,8 @@ class Complex < Numeric
310
315
  # rdoc-file=complex.c
311
316
  # - complex == object -> true or false
312
317
  # -->
313
- # Returns `true` if `self.real == object.real` and `self.imag == object.imag`:
318
+ # Returns `true` if <code>self.real == object.real</code> and <code>self.imag ==
319
+ # object.imag</code>:
314
320
  #
315
321
  # Complex.rect(2, 3) == Complex.rect(2.0, 3.0) # => true
316
322
  #
@@ -390,21 +396,23 @@ class Complex < Numeric
390
396
  def coerce: (Numeric) -> [ Complex, Complex ]
391
397
 
392
398
  # <!-- rdoc-file=complex.c -->
393
- # Returns the conjugate of `self`, `Complex.rect(self.imag, self.real)`:
399
+ # Returns the conjugate of `self`, <code>Complex.rect(self.imag,
400
+ # self.real)</code>:
394
401
  #
395
402
  # Complex.rect(1, 2).conj # => (1-2i)
396
403
  #
397
- def conj: () -> Complex
404
+ def conj: () -> self
398
405
 
399
406
  # <!--
400
407
  # rdoc-file=complex.c
401
408
  # - conj -> complex
402
409
  # -->
403
- # Returns the conjugate of `self`, `Complex.rect(self.imag, self.real)`:
410
+ # Returns the conjugate of `self`, <code>Complex.rect(self.imag,
411
+ # self.real)</code>:
404
412
  #
405
413
  # Complex.rect(1, 2).conj # => (1-2i)
406
414
  #
407
- def conjugate: () -> Complex
415
+ def conjugate: () -> self
408
416
 
409
417
  # <!--
410
418
  # rdoc-file=complex.c
@@ -412,11 +420,11 @@ class Complex < Numeric
412
420
  # -->
413
421
  # Returns the denominator of `self`, which is the [least common
414
422
  # multiple](https://en.wikipedia.org/wiki/Least_common_multiple) of
415
- # `self.real.denominator` and `self.imag.denominator`:
423
+ # <code>self.real.denominator</code> and <code>self.imag.denominator</code>:
416
424
  #
417
425
  # Complex.rect(Rational(1, 2), Rational(2, 3)).denominator # => 6
418
426
  #
419
- # Note that `n.denominator` of a non-rational numeric is `1`.
427
+ # Note that <code>n.denominator</code> of a non-rational numeric is `1`.
420
428
  #
421
429
  # Related: Complex#numerator.
422
430
  #
@@ -426,15 +434,11 @@ class Complex < Numeric
426
434
 
427
435
  def divmod: (Numeric) -> bot
428
436
 
429
- def dup: () -> self
430
-
431
- def eql?: (untyped) -> bool
432
-
433
437
  # <!--
434
438
  # rdoc-file=complex.c
435
439
  # - fdiv(numeric) -> new_complex
436
440
  # -->
437
- # Returns `Complex.rect(self.real/numeric, self.imag/numeric)`:
441
+ # Returns <code>Complex.rect(self.real/numeric, self.imag/numeric)</code>:
438
442
  #
439
443
  # Complex.rect(11, 22).fdiv(3) # => (3.6666666666666665+7.333333333333333i)
440
444
  #
@@ -444,8 +448,8 @@ class Complex < Numeric
444
448
  # rdoc-file=complex.c
445
449
  # - finite? -> true or false
446
450
  # -->
447
- # Returns `true` if both `self.real.finite?` and `self.imag.finite?` are true,
448
- # `false` otherwise:
451
+ # Returns `true` if both <code>self.real.finite?</code> and
452
+ # <code>self.imag.finite?</code> are true, `false` otherwise:
449
453
  #
450
454
  # Complex.rect(1, 1).finite? # => true
451
455
  # Complex.rect(Float::INFINITY, 0).finite? # => false
@@ -469,6 +473,19 @@ class Complex < Numeric
469
473
  #
470
474
  def hash: () -> Integer
471
475
 
476
+ # <!--
477
+ # rdoc-file=numeric.c
478
+ # - i -> complex
479
+ # -->
480
+ # Returns <code>Complex(0, self)</code>:
481
+ #
482
+ # 2.i # => (0+2i)
483
+ # -2.i # => (0-2i)
484
+ # 2.0.i # => (0+2.0i)
485
+ # Rational(1, 2).i # => (0+(1/2)*i)
486
+ # Complex(3, 4).i # Raises NoMethodError.
487
+ #
488
+ %a{annotate:rdoc:copy:Numeric#i}
472
489
  def i: () -> bot
473
490
 
474
491
  # <!-- rdoc-file=complex.c -->
@@ -506,8 +523,8 @@ class Complex < Numeric
506
523
  # rdoc-file=complex.c
507
524
  # - infinite? -> 1 or nil
508
525
  # -->
509
- # Returns `1` if either `self.real.infinite?` or `self.imag.infinite?` is true,
510
- # `nil` otherwise:
526
+ # Returns `1` if either <code>self.real.infinite?</code> or
527
+ # <code>self.imag.infinite?</code> is true, `nil` otherwise:
511
528
  #
512
529
  # Complex.rect(Float::INFINITY, 0).infinite? # => 1
513
530
  # Complex.rect(1, 1).infinite? # => nil
@@ -530,8 +547,6 @@ class Complex < Numeric
530
547
  #
531
548
  def inspect: () -> String
532
549
 
533
- def integer?: () -> bool
534
-
535
550
  # <!-- rdoc-file=complex.c -->
536
551
  # Returns the absolute value (magnitude) for `self`; see [polar
537
552
  # coordinates](rdoc-ref:Complex@Polar+Coordinates):
@@ -550,8 +565,6 @@ class Complex < Numeric
550
565
 
551
566
  def negative?: () -> bot
552
567
 
553
- def nonzero?: () -> self?
554
-
555
568
  # <!--
556
569
  # rdoc-file=complex.c
557
570
  # - numerator -> new_complex
@@ -567,7 +580,7 @@ class Complex < Numeric
567
580
  # In this example, the lowest common denominator of the two parts is 12; the two
568
581
  # converted parts may be thought of as Rational(8, 12) and Rational(9, 12),
569
582
  # whose numerators, respectively, are 8 and 9; so the returned value of
570
- # `c.numerator` is `Complex.rect(8, 9)`.
583
+ # <code>c.numerator</code> is <code>Complex.rect(8, 9)</code>.
571
584
  #
572
585
  # Related: Complex#denominator.
573
586
  #
@@ -591,7 +604,7 @@ class Complex < Numeric
591
604
  # rdoc-file=complex.c
592
605
  # - polar -> array
593
606
  # -->
594
- # Returns the array `[self.abs, self.arg]`:
607
+ # Returns the array <code>[self.abs, self.arg]</code>:
595
608
  #
596
609
  # Complex.polar(1, 2).polar # => [1.0, 2.0]
597
610
  #
@@ -626,17 +639,18 @@ class Complex < Numeric
626
639
  # - rationalize(epsilon = nil) -> rational
627
640
  # -->
628
641
  # Returns a Rational object whose value is exactly or approximately equivalent
629
- # to that of `self.real`.
642
+ # to that of <code>self.real</code>.
630
643
  #
631
644
  # With no argument `epsilon` given, returns a Rational object whose value is
632
- # exactly equal to that of `self.real.rationalize`:
645
+ # exactly equal to that of <code>self.real.rationalize</code>:
633
646
  #
634
647
  # Complex.rect(1, 0).rationalize # => (1/1)
635
648
  # Complex.rect(1, Rational(0, 1)).rationalize # => (1/1)
636
649
  # Complex.rect(3.14159, 0).rationalize # => (314159/100000)
637
650
  #
638
651
  # With argument `epsilon` given, returns a Rational object whose value is
639
- # exactly or approximately equal to that of `self.real` to the given precision:
652
+ # exactly or approximately equal to that of <code>self.real</code> to the given
653
+ # precision:
640
654
  #
641
655
  # Complex.rect(3.14159, 0).rationalize(0.1) # => (16/5)
642
656
  # Complex.rect(3.14159, 0).rationalize(0.01) # => (22/7)
@@ -697,7 +711,7 @@ class Complex < Numeric
697
711
  # rdoc-file=complex.c
698
712
  # - rect -> array
699
713
  # -->
700
- # Returns the array `[self.real, self.imag]`:
714
+ # Returns the array <code>[self.real, self.imag]</code>:
701
715
  #
702
716
  # Complex.rect(1, 2).rect # => [1, 2]
703
717
  #
@@ -731,13 +745,13 @@ class Complex < Numeric
731
745
  # rdoc-file=complex.c
732
746
  # - to_f -> float
733
747
  # -->
734
- # Returns the value of `self.real` as a Float, if possible:
748
+ # Returns the value of <code>self.real</code> as a Float, if possible:
735
749
  #
736
750
  # Complex.rect(1, 0).to_f # => 1.0
737
751
  # Complex.rect(1, Rational(0, 1)).to_f # => 1.0
738
752
  #
739
- # Raises RangeError if `self.imag` is not exactly zero (either `Integer(0)` or
740
- # `Rational(0, *n*)`).
753
+ # Raises RangeError if <code>self.imag</code> is not exactly zero (either
754
+ # <code>Integer(0)</code> or <code>Rational(0, _n_)</code>).
741
755
  #
742
756
  def to_f: () -> Float
743
757
 
@@ -745,30 +759,29 @@ class Complex < Numeric
745
759
  # rdoc-file=complex.c
746
760
  # - to_i -> integer
747
761
  # -->
748
- # Returns the value of `self.real` as an Integer, if possible:
762
+ # Returns the value of <code>self.real</code> as an Integer, if possible:
749
763
  #
750
764
  # Complex.rect(1, 0).to_i # => 1
751
765
  # Complex.rect(1, Rational(0, 1)).to_i # => 1
752
766
  #
753
- # Raises RangeError if `self.imag` is not exactly zero (either `Integer(0)` or
754
- # `Rational(0, *n*)`).
767
+ # Raises RangeError if <code>self.imag</code> is not exactly zero (either
768
+ # <code>Integer(0)</code> or <code>Rational(0, _n_)</code>).
755
769
  #
756
770
  def to_i: () -> Integer
757
771
 
758
- alias to_int to_i
759
-
760
772
  # <!--
761
773
  # rdoc-file=complex.c
762
774
  # - to_r -> rational
763
775
  # -->
764
- # Returns the value of `self.real` as a Rational, if possible:
776
+ # Returns the value of <code>self.real</code> as a Rational, if possible:
765
777
  #
766
778
  # Complex.rect(1, 0).to_r # => (1/1)
767
779
  # Complex.rect(1, Rational(0, 1)).to_r # => (1/1)
768
780
  # Complex.rect(1, 0.0).to_r # => (1/1)
769
781
  #
770
- # Raises RangeError if `self.imag` is not exactly zero (either `Integer(0)` or
771
- # `Rational(0, *n*)`) and `self.imag.to_r` is not exactly zero.
782
+ # Raises RangeError if <code>self.imag</code> is not exactly zero (either
783
+ # <code>Integer(0)</code> or <code>Rational(0, _n_)</code>) and
784
+ # <code>self.imag.to_r</code> is not exactly zero.
772
785
  #
773
786
  # Related: Complex#rationalize.
774
787
  #
@@ -789,12 +802,10 @@ class Complex < Numeric
789
802
  def to_s: () -> String
790
803
 
791
804
  def truncate: (?Integer) -> bot
792
-
793
- def zero?: () -> bool
794
805
  end
795
806
 
796
807
  # <!-- rdoc-file=complex.c -->
797
- # Equivalent to `Complex.rect(0, 1)`:
808
+ # Equivalent to <code>Complex.rect(0, 1)</code>:
798
809
  #
799
810
  # Complex::I # => (0+1i)
800
811
  #