rbs 4.0.0.dev.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 (281) 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 +18 -11
  5. data/.github/workflows/comments.yml +5 -3
  6. data/.github/workflows/dependabot.yml +2 -2
  7. data/.github/workflows/ruby.yml +27 -34
  8. data/.github/workflows/rust.yml +95 -0
  9. data/.github/workflows/typecheck.yml +2 -2
  10. data/.github/workflows/windows.yml +2 -2
  11. data/.rubocop.yml +1 -1
  12. data/CHANGELOG.md +323 -0
  13. data/README.md +1 -1
  14. data/Rakefile +43 -33
  15. data/Steepfile +1 -0
  16. data/config.yml +426 -24
  17. data/core/array.rbs +307 -227
  18. data/core/basic_object.rbs +9 -8
  19. data/core/binding.rbs +0 -2
  20. data/core/builtin.rbs +2 -2
  21. data/core/class.rbs +6 -5
  22. data/core/comparable.rbs +55 -34
  23. data/core/complex.rbs +104 -78
  24. data/core/dir.rbs +61 -49
  25. data/core/encoding.rbs +12 -15
  26. data/core/enumerable.rbs +179 -87
  27. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  28. data/core/enumerator.rbs +65 -2
  29. data/core/errno.rbs +11 -2
  30. data/core/errors.rbs +58 -29
  31. data/core/exception.rbs +13 -13
  32. data/core/fiber.rbs +74 -54
  33. data/core/file.rbs +280 -177
  34. data/core/file_test.rbs +3 -3
  35. data/core/float.rbs +257 -92
  36. data/core/gc.rbs +425 -281
  37. data/core/hash.rbs +1045 -739
  38. data/core/integer.rbs +135 -137
  39. data/core/io/buffer.rbs +53 -42
  40. data/core/io/wait.rbs +13 -35
  41. data/core/io.rbs +192 -144
  42. data/core/kernel.rbs +216 -155
  43. data/core/marshal.rbs +4 -4
  44. data/core/match_data.rbs +15 -13
  45. data/core/math.rbs +107 -66
  46. data/core/method.rbs +69 -33
  47. data/core/module.rbs +244 -106
  48. data/core/nil_class.rbs +7 -6
  49. data/core/numeric.rbs +74 -63
  50. data/core/object.rbs +9 -11
  51. data/core/object_space.rbs +30 -23
  52. data/core/pathname.rbs +1322 -0
  53. data/core/proc.rbs +95 -58
  54. data/core/process.rbs +222 -202
  55. data/core/ractor.rbs +371 -515
  56. data/core/random.rbs +21 -3
  57. data/core/range.rbs +159 -57
  58. data/core/rational.rbs +60 -89
  59. data/core/rbs/unnamed/argf.rbs +60 -53
  60. data/core/rbs/unnamed/env_class.rbs +19 -14
  61. data/core/rbs/unnamed/main_class.rbs +123 -0
  62. data/core/rbs/unnamed/random.rbs +11 -118
  63. data/core/regexp.rbs +258 -214
  64. data/core/ruby.rbs +53 -0
  65. data/core/ruby_vm.rbs +38 -34
  66. data/core/rubygems/config_file.rbs +5 -5
  67. data/core/rubygems/errors.rbs +4 -71
  68. data/core/rubygems/requirement.rbs +5 -5
  69. data/core/rubygems/rubygems.rbs +16 -82
  70. data/core/rubygems/version.rbs +2 -3
  71. data/core/set.rbs +490 -360
  72. data/core/signal.rbs +26 -16
  73. data/core/string.rbs +3234 -1285
  74. data/core/struct.rbs +27 -26
  75. data/core/symbol.rbs +41 -34
  76. data/core/thread.rbs +135 -67
  77. data/core/time.rbs +81 -50
  78. data/core/trace_point.rbs +41 -35
  79. data/core/true_class.rbs +2 -2
  80. data/core/unbound_method.rbs +24 -16
  81. data/core/warning.rbs +7 -7
  82. data/docs/aliases.md +79 -0
  83. data/docs/collection.md +3 -3
  84. data/docs/config.md +171 -0
  85. data/docs/encoding.md +56 -0
  86. data/docs/gem.md +0 -1
  87. data/docs/inline.md +576 -0
  88. data/docs/sigs.md +3 -3
  89. data/docs/syntax.md +46 -16
  90. data/docs/type_fingerprint.md +21 -0
  91. data/exe/rbs +1 -1
  92. data/ext/rbs_extension/ast_translation.c +544 -116
  93. data/ext/rbs_extension/ast_translation.h +3 -0
  94. data/ext/rbs_extension/class_constants.c +16 -2
  95. data/ext/rbs_extension/class_constants.h +8 -0
  96. data/ext/rbs_extension/extconf.rb +5 -1
  97. data/ext/rbs_extension/legacy_location.c +33 -56
  98. data/ext/rbs_extension/legacy_location.h +37 -0
  99. data/ext/rbs_extension/main.c +44 -35
  100. data/include/rbs/ast.h +448 -173
  101. data/include/rbs/defines.h +27 -0
  102. data/include/rbs/lexer.h +30 -11
  103. data/include/rbs/location.h +25 -44
  104. data/include/rbs/parser.h +6 -6
  105. data/include/rbs/string.h +0 -2
  106. data/include/rbs/util/rbs_allocator.h +34 -13
  107. data/include/rbs/util/rbs_assert.h +12 -1
  108. data/include/rbs/util/rbs_constant_pool.h +0 -3
  109. data/include/rbs/util/rbs_encoding.h +2 -0
  110. data/include/rbs/util/rbs_unescape.h +2 -1
  111. data/include/rbs.h +8 -0
  112. data/lib/rbs/ast/annotation.rb +1 -1
  113. data/lib/rbs/ast/comment.rb +1 -1
  114. data/lib/rbs/ast/declarations.rb +10 -10
  115. data/lib/rbs/ast/members.rb +14 -14
  116. data/lib/rbs/ast/ruby/annotations.rb +293 -3
  117. data/lib/rbs/ast/ruby/comment_block.rb +24 -0
  118. data/lib/rbs/ast/ruby/declarations.rb +198 -3
  119. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
  120. data/lib/rbs/ast/ruby/members.rb +532 -22
  121. data/lib/rbs/ast/type_param.rb +24 -4
  122. data/lib/rbs/buffer.rb +20 -15
  123. data/lib/rbs/cli/diff.rb +16 -15
  124. data/lib/rbs/cli/validate.rb +38 -106
  125. data/lib/rbs/cli.rb +52 -19
  126. data/lib/rbs/collection/config/lockfile_generator.rb +14 -2
  127. data/lib/rbs/collection/sources/git.rb +1 -0
  128. data/lib/rbs/definition.rb +1 -1
  129. data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
  130. data/lib/rbs/definition_builder/method_builder.rb +20 -0
  131. data/lib/rbs/definition_builder.rb +147 -25
  132. data/lib/rbs/diff.rb +7 -1
  133. data/lib/rbs/environment.rb +227 -74
  134. data/lib/rbs/environment_loader.rb +0 -6
  135. data/lib/rbs/errors.rb +27 -18
  136. data/lib/rbs/inline_parser.rb +342 -6
  137. data/lib/rbs/location_aux.rb +1 -1
  138. data/lib/rbs/locator.rb +5 -1
  139. data/lib/rbs/method_type.rb +5 -3
  140. data/lib/rbs/parser_aux.rb +20 -7
  141. data/lib/rbs/prototype/helpers.rb +57 -0
  142. data/lib/rbs/prototype/rb.rb +3 -28
  143. data/lib/rbs/prototype/rbi.rb +3 -20
  144. data/lib/rbs/prototype/runtime.rb +8 -0
  145. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  146. data/lib/rbs/resolver/type_name_resolver.rb +116 -38
  147. data/lib/rbs/subtractor.rb +3 -1
  148. data/lib/rbs/test/type_check.rb +19 -2
  149. data/lib/rbs/type_name.rb +1 -1
  150. data/lib/rbs/types.rb +88 -78
  151. data/lib/rbs/unit_test/type_assertions.rb +35 -8
  152. data/lib/rbs/validator.rb +2 -2
  153. data/lib/rbs/version.rb +1 -1
  154. data/lib/rbs.rb +1 -2
  155. data/lib/rdoc/discover.rb +1 -1
  156. data/lib/rdoc_plugin/parser.rb +1 -1
  157. data/rbs.gemspec +4 -3
  158. data/rust/.gitignore +1 -0
  159. data/rust/Cargo.lock +378 -0
  160. data/rust/Cargo.toml +7 -0
  161. data/rust/ruby-rbs/Cargo.toml +22 -0
  162. data/rust/ruby-rbs/build.rs +764 -0
  163. data/rust/ruby-rbs/examples/locations.rs +60 -0
  164. data/rust/ruby-rbs/src/lib.rs +1 -0
  165. data/rust/ruby-rbs/src/node/mod.rs +742 -0
  166. data/rust/ruby-rbs/tests/sanity.rs +47 -0
  167. data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
  168. data/rust/ruby-rbs-sys/Cargo.toml +23 -0
  169. data/rust/ruby-rbs-sys/build.rs +204 -0
  170. data/rust/ruby-rbs-sys/src/lib.rs +50 -0
  171. data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
  172. data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
  173. data/rust/ruby-rbs-sys/wrapper.h +1 -0
  174. data/schema/typeParam.json +17 -1
  175. data/sig/ast/ruby/annotations.rbs +315 -4
  176. data/sig/ast/ruby/comment_block.rbs +8 -0
  177. data/sig/ast/ruby/declarations.rbs +102 -4
  178. data/sig/ast/ruby/members.rbs +108 -2
  179. data/sig/cli/diff.rbs +5 -11
  180. data/sig/cli/validate.rbs +12 -8
  181. data/sig/cli.rbs +18 -18
  182. data/sig/definition.rbs +6 -1
  183. data/sig/definition_builder.rbs +2 -0
  184. data/sig/environment.rbs +70 -12
  185. data/sig/errors.rbs +13 -14
  186. data/sig/inline_parser.rbs +39 -2
  187. data/sig/locator.rbs +0 -2
  188. data/sig/manifest.yaml +0 -1
  189. data/sig/method_builder.rbs +3 -1
  190. data/sig/parser.rbs +31 -13
  191. data/sig/prototype/helpers.rbs +2 -0
  192. data/sig/resolver/type_name_resolver.rbs +35 -7
  193. data/sig/source.rbs +3 -3
  194. data/sig/type_param.rbs +13 -8
  195. data/sig/types.rbs +6 -7
  196. data/sig/unit_test/spy.rbs +0 -8
  197. data/sig/unit_test/type_assertions.rbs +11 -0
  198. data/src/ast.c +410 -153
  199. data/src/lexer.c +1392 -1313
  200. data/src/lexer.re +3 -0
  201. data/src/lexstate.c +58 -37
  202. data/src/location.c +8 -48
  203. data/src/parser.c +977 -516
  204. data/src/string.c +0 -48
  205. data/src/util/rbs_allocator.c +89 -71
  206. data/src/util/rbs_assert.c +1 -1
  207. data/src/util/rbs_buffer.c +2 -2
  208. data/src/util/rbs_constant_pool.c +10 -14
  209. data/src/util/rbs_encoding.c +4 -8
  210. data/src/util/rbs_unescape.c +56 -20
  211. data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
  212. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  213. data/stdlib/cgi/0/core.rbs +9 -393
  214. data/stdlib/cgi/0/manifest.yaml +1 -0
  215. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  216. data/stdlib/coverage/0/coverage.rbs +7 -4
  217. data/stdlib/date/0/date.rbs +92 -79
  218. data/stdlib/date/0/date_time.rbs +25 -24
  219. data/stdlib/delegate/0/delegator.rbs +10 -7
  220. data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
  221. data/stdlib/digest/0/digest.rbs +110 -0
  222. data/stdlib/erb/0/erb.rbs +748 -347
  223. data/stdlib/etc/0/etc.rbs +55 -50
  224. data/stdlib/fileutils/0/fileutils.rbs +158 -139
  225. data/stdlib/forwardable/0/forwardable.rbs +13 -10
  226. data/stdlib/io-console/0/io-console.rbs +2 -2
  227. data/stdlib/json/0/json.rbs +217 -136
  228. data/stdlib/monitor/0/monitor.rbs +3 -3
  229. data/stdlib/net-http/0/net-http.rbs +162 -134
  230. data/stdlib/objspace/0/objspace.rbs +17 -34
  231. data/stdlib/open-uri/0/open-uri.rbs +48 -8
  232. data/stdlib/open3/0/open3.rbs +469 -10
  233. data/stdlib/openssl/0/openssl.rbs +475 -357
  234. data/stdlib/optparse/0/optparse.rbs +26 -17
  235. data/stdlib/pathname/0/pathname.rbs +11 -1381
  236. data/stdlib/pp/0/pp.rbs +9 -8
  237. data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
  238. data/stdlib/pstore/0/pstore.rbs +35 -30
  239. data/stdlib/psych/0/psych.rbs +65 -12
  240. data/stdlib/psych/0/store.rbs +2 -4
  241. data/stdlib/pty/0/pty.rbs +9 -6
  242. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  243. data/stdlib/rdoc/0/code_object.rbs +2 -1
  244. data/stdlib/rdoc/0/parser.rbs +1 -1
  245. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  246. data/stdlib/rdoc/0/store.rbs +1 -1
  247. data/stdlib/resolv/0/resolv.rbs +25 -68
  248. data/stdlib/ripper/0/ripper.rbs +22 -19
  249. data/stdlib/securerandom/0/manifest.yaml +2 -0
  250. data/stdlib/securerandom/0/securerandom.rbs +7 -20
  251. data/stdlib/shellwords/0/shellwords.rbs +2 -2
  252. data/stdlib/singleton/0/singleton.rbs +3 -0
  253. data/stdlib/socket/0/addrinfo.rbs +7 -7
  254. data/stdlib/socket/0/basic_socket.rbs +3 -3
  255. data/stdlib/socket/0/ip_socket.rbs +10 -8
  256. data/stdlib/socket/0/socket.rbs +23 -10
  257. data/stdlib/socket/0/tcp_server.rbs +1 -1
  258. data/stdlib/socket/0/tcp_socket.rbs +11 -3
  259. data/stdlib/socket/0/udp_socket.rbs +1 -1
  260. data/stdlib/socket/0/unix_server.rbs +1 -1
  261. data/stdlib/stringio/0/stringio.rbs +1177 -85
  262. data/stdlib/strscan/0/string_scanner.rbs +27 -25
  263. data/stdlib/tempfile/0/tempfile.rbs +25 -21
  264. data/stdlib/time/0/time.rbs +8 -6
  265. data/stdlib/timeout/0/timeout.rbs +63 -7
  266. data/stdlib/tsort/0/cyclic.rbs +3 -0
  267. data/stdlib/tsort/0/tsort.rbs +7 -6
  268. data/stdlib/uri/0/common.rbs +42 -20
  269. data/stdlib/uri/0/file.rbs +3 -3
  270. data/stdlib/uri/0/generic.rbs +26 -18
  271. data/stdlib/uri/0/http.rbs +2 -2
  272. data/stdlib/uri/0/ldap.rbs +2 -2
  273. data/stdlib/uri/0/mailto.rbs +3 -3
  274. data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
  275. data/stdlib/zlib/0/deflate.rbs +4 -3
  276. data/stdlib/zlib/0/gzip_reader.rbs +6 -6
  277. data/stdlib/zlib/0/gzip_writer.rbs +14 -12
  278. data/stdlib/zlib/0/inflate.rbs +1 -1
  279. data/stdlib/zlib/0/need_dict.rbs +1 -1
  280. data/stdlib/zlib/0/zstream.rbs +1 -0
  281. metadata +50 -6
data/core/module.rbs CHANGED
@@ -6,7 +6,7 @@
6
6
  # methods may not. (See Module#module_function.)
7
7
  #
8
8
  # In the descriptions that follow, the parameter *sym* refers to a symbol, which
9
- # is either a quoted string or a Symbol (such as `:name`).
9
+ # is either a quoted string or a Symbol (such as <code>:name</code>).
10
10
  #
11
11
  # module Mod
12
12
  # include Math
@@ -79,7 +79,7 @@ class Module < Object
79
79
  # using B
80
80
  # p Module.used_modules
81
81
  #
82
- # *produces:*
82
+ # <em>produces:</em>
83
83
  #
84
84
  # [B, A]
85
85
  #
@@ -106,7 +106,7 @@ class Module < Object
106
106
  # using B
107
107
  # p Module.used_refinements
108
108
  #
109
- # *produces:*
109
+ # <em>produces:</em>
110
110
  #
111
111
  # [#<refinement:Object@B>, #<refinement:Object@A>]
112
112
  #
@@ -114,12 +114,15 @@ class Module < Object
114
114
 
115
115
  # <!--
116
116
  # rdoc-file=object.c
117
- # - mod < other -> true, false, or nil
117
+ # - self < other -> true, false, or nil
118
118
  # -->
119
- # Returns true if *mod* is a subclass of *other*. Returns `false` if *mod* is
120
- # the same as *other* or *mod* is an ancestor of *other*. Returns `nil` if
121
- # there's no relationship between the two. (Think of the relationship in terms
122
- # of the class definition: "class A < B" implies "A < B".)
119
+ # Returns whether `self` is a subclass of `other`, or `nil` if there is no
120
+ # relationship between the two:
121
+ #
122
+ # Float < Numeric # => true
123
+ # Numeric < Float # => false
124
+ # Float < Float # => false
125
+ # Float < Hash # => nil
123
126
  #
124
127
  def <: (Module other) -> bool?
125
128
 
@@ -135,14 +138,30 @@ class Module < Object
135
138
 
136
139
  # <!--
137
140
  # rdoc-file=object.c
138
- # - module <=> other_module -> -1, 0, +1, or nil
141
+ # - self <=> other -> -1, 0, 1, or nil
139
142
  # -->
140
- # Comparison---Returns -1, 0, +1 or nil depending on whether `module` includes
141
- # `other_module`, they are the same, or if `module` is included by
142
- # `other_module`.
143
+ # Compares `self` and `other`.
144
+ #
145
+ # Returns:
146
+ #
147
+ # * <code>-1</code>, if `self` includes `other`, if or `self` is a subclass of
148
+ # `other`.
149
+ # * `0`, if `self` and `other` are the same.
150
+ # * `1`, if `other` includes `self`, or if `other` is a subclass of `self`.
151
+ # * `nil`, if none of the above is true.
152
+ #
153
+ # Examples:
143
154
  #
144
- # Returns `nil` if `module` has no relationship with `other_module`, if
145
- # `other_module` is not a module, or if the two values are incomparable.
155
+ # # Class Array includes module Enumerable.
156
+ # Array <=> Enumerable # => -1
157
+ # Enumerable <=> Enumerable # => 0
158
+ # Enumerable <=> Array # => 1
159
+ # # Class File is a subclass of class IO.
160
+ # File <=> IO # => -1
161
+ # File <=> File # => 0
162
+ # IO <=> File # => 1
163
+ # # Class File has no relationship to class String.
164
+ # File <=> String # => nil
146
165
  #
147
166
  def <=>: (untyped other) -> Integer?
148
167
 
@@ -157,8 +176,8 @@ class Module < Object
157
176
  # classes to provide class-specific meaning.
158
177
  #
159
178
  # Unlike #==, the #equal? method should never be overridden by subclasses as it
160
- # is used to determine object identity (that is, `a.equal?(b)` if and only if
161
- # `a` is the same object as `b`):
179
+ # is used to determine object identity (that is, <code>a.equal?(b)</code> if and
180
+ # only if `a` is the same object as `b`):
162
181
  #
163
182
  # obj = "a"
164
183
  # other = obj.dup
@@ -231,7 +250,7 @@ class Module < Object
231
250
  # include Mod
232
251
  # exit(99)
233
252
  #
234
- # *produces:*
253
+ # <em>produces:</em>
235
254
  #
236
255
  # Exiting with code 99
237
256
  #
@@ -266,7 +285,7 @@ class Module < Object
266
285
  # module to *mod* if this module has not already been added to *mod* or one of
267
286
  # its ancestors. See also Module#include.
268
287
  #
269
- def append_features: (Module arg0) -> self
288
+ private def append_features: (Module arg0) -> self
270
289
 
271
290
  # <!--
272
291
  # rdoc-file=object.c
@@ -274,10 +293,10 @@ class Module < Object
274
293
  # - attr_accessor(string, ...) -> array
275
294
  # -->
276
295
  # Defines a named attribute for this module, where the name is
277
- # *symbol.*`id2name`, creating an instance variable (`@name`) and a
278
- # corresponding access method to read it. Also creates a method called `name=`
279
- # to set the attribute. String arguments are converted to symbols. Returns an
280
- # array of defined method names as symbols.
296
+ # <em>symbol.</em>`id2name`, creating an instance variable (<code>@name</code>)
297
+ # and a corresponding access method to read it. Also creates a method called
298
+ # <code>name=</code> to set the attribute. String arguments are converted to
299
+ # symbols. Returns an array of defined method names as symbols.
281
300
  #
282
301
  # module Mod
283
302
  # attr_accessor(:one, :two) #=> [:one, :one=, :two, :two=]
@@ -294,8 +313,8 @@ class Module < Object
294
313
  # - attr(string, ...) -> array
295
314
  # -->
296
315
  # Creates instance variables and corresponding methods that return the value of
297
- # each instance variable. Equivalent to calling ```attr`*:name*'' on each name
298
- # in turn. String arguments are converted to symbols. Returns an array of
316
+ # each instance variable. Equivalent to calling ```attr`<em>:name</em>'' on each
317
+ # name in turn. String arguments are converted to symbols. Returns an array of
299
318
  # defined method names as symbols.
300
319
  #
301
320
  def attr_reader: (*interned arg0) -> Array[Symbol]
@@ -306,8 +325,8 @@ class Module < Object
306
325
  # - attr_writer(string, ...) -> array
307
326
  # -->
308
327
  # Creates an accessor method to allow assignment to the attribute
309
- # *symbol*`.id2name`. String arguments are converted to symbols. Returns an
310
- # array of defined method names as symbols.
328
+ # *symbol*<code>.id2name</code>. String arguments are converted to symbols.
329
+ # Returns an array of defined method names as symbols.
311
330
  #
312
331
  def attr_writer: (*interned arg0) -> Array[Symbol]
313
332
 
@@ -328,6 +347,8 @@ class Module < Object
328
347
  # replaced with *filename*. If *const* is defined but not as autoload, does
329
348
  # nothing.
330
349
  #
350
+ # Files that are currently being loaded must not be registered for autoload.
351
+ #
331
352
  def autoload: (interned _module, String filename) -> NilClass
332
353
 
333
354
  # <!--
@@ -370,7 +391,7 @@ class Module < Object
370
391
  # puts Thing.new.hello()
371
392
  # Thing.module_eval("invalid code", "dummy", 123)
372
393
  #
373
- # *produces:*
394
+ # <em>produces:</em>
374
395
  #
375
396
  # Hello there!
376
397
  # dummy:123:in `module_eval': undefined local variable
@@ -392,7 +413,7 @@ class Module < Object
392
413
  # }
393
414
  # puts Thing.new.hello()
394
415
  #
395
- # *produces:*
416
+ # <em>produces:</em>
396
417
  #
397
418
  # Hello there!
398
419
  #
@@ -420,8 +441,8 @@ class Module < Object
420
441
  # - mod.class_variable_get(string) -> obj
421
442
  # -->
422
443
  # Returns the value of the given class variable (or throws a NameError
423
- # exception). The `@@` part of the variable name should be included for regular
424
- # class variables. String arguments are converted to symbols.
444
+ # exception). The <code>@@</code> part of the variable name should be included
445
+ # for regular class variables. String arguments are converted to symbols.
425
446
  #
426
447
  # class Fred
427
448
  # @@foo = 99
@@ -483,11 +504,36 @@ class Module < Object
483
504
  # FOO = 1
484
505
  # end
485
506
  #
486
- # *produces:*
507
+ # <em>produces:</em>
487
508
  #
488
509
  # Added :FOO
489
510
  #
490
- def const_added: (Symbol) -> void
511
+ # If we define a class using the `class` keyword, `const_added` runs before
512
+ # `inherited`:
513
+ #
514
+ # module M
515
+ # def self.const_added(const_name)
516
+ # super
517
+ # p :const_added
518
+ # end
519
+ #
520
+ # parent = Class.new do
521
+ # def self.inherited(subclass)
522
+ # super
523
+ # p :inherited
524
+ # end
525
+ # end
526
+ #
527
+ # class Child < parent
528
+ # end
529
+ # end
530
+ #
531
+ # <em>produces:</em>
532
+ #
533
+ # :const_added
534
+ # :inherited
535
+ #
536
+ private def const_added: (Symbol) -> void
491
537
 
492
538
  # <!--
493
539
  # rdoc-file=object.c
@@ -590,10 +636,11 @@ class Module < Object
590
636
  #
591
637
  # In the next example, when a reference is made to an undefined constant,
592
638
  # `const_missing` attempts to load a file whose path is the lowercase version of
593
- # the constant name (thus class `Fred` is assumed to be in file `fred.rb`). If
594
- # defined as a side-effect of loading the file, the method returns the value
595
- # stored in the constant. This implements an autoload feature similar to
596
- # Kernel#autoload and Module#autoload, though it differs in important ways.
639
+ # the constant name (thus class `Fred` is assumed to be in file
640
+ # <code>fred.rb</code>). If defined as a side-effect of loading the file, the
641
+ # method returns the value stored in the constant. This implements an autoload
642
+ # feature similar to Kernel#autoload and Module#autoload, though it differs in
643
+ # important ways.
597
644
  #
598
645
  # def Object.const_missing(name)
599
646
  # @looked_for ||= {}
@@ -635,7 +682,8 @@ class Module < Object
635
682
  # If the constant is found, but its source location can not be extracted
636
683
  # (constant is defined in C code), empty array is returned.
637
684
  #
638
- # *inherit* specifies whether to lookup in `mod.ancestors` (`true` by default).
685
+ # *inherit* specifies whether to lookup in <code>mod.ancestors</code> (`true` by
686
+ # default).
639
687
  #
640
688
  # # test.rb:
641
689
  # class A # line 1
@@ -724,7 +772,7 @@ class Module < Object
724
772
  # a.create_method(:betty) { p self }
725
773
  # a.betty
726
774
  #
727
- # *produces:*
775
+ # <em>produces:</em>
728
776
  #
729
777
  # In Fred
730
778
  # Charge it!
@@ -753,8 +801,6 @@ class Module < Object
753
801
  #
754
802
  def deprecate_constant: (*interned) -> self
755
803
 
756
- def eql?: (untyped other) -> bool
757
-
758
804
  def equal?: (untyped other) -> bool
759
805
 
760
806
  # <!--
@@ -778,12 +824,12 @@ class Module < Object
778
824
  # (s = Array.new).extend Picky # Call Object.extend
779
825
  # (s = "quick brown fox").extend Picky
780
826
  #
781
- # *produces:*
827
+ # <em>produces:</em>
782
828
  #
783
829
  # Picky added to Array
784
830
  # Can't add Picky to a String
785
831
  #
786
- def extend_object: (untyped arg0) -> untyped
832
+ private def extend_object: (untyped arg0) -> untyped
787
833
 
788
834
  # <!--
789
835
  # rdoc-file=object.c
@@ -801,7 +847,7 @@ class Module < Object
801
847
  # end
802
848
  # # => prints "A extended in Enumerable"
803
849
  #
804
- def extended: (Module othermod) -> untyped
850
+ private def extended: (Module othermod) -> untyped
805
851
 
806
852
  # <!--
807
853
  # rdoc-file=object.c
@@ -846,8 +892,8 @@ class Module < Object
846
892
  # - included(othermod)
847
893
  # -->
848
894
  # Callback invoked whenever the receiver is included in another module or class.
849
- # This should be used in preference to `Module.append_features` if your code
850
- # wants to perform some action when a module is included in another.
895
+ # This should be used in preference to <code>Module.append_features</code> if
896
+ # your code wants to perform some action when a module is included in another.
851
897
  #
852
898
  # module A
853
899
  # def A.included(mod)
@@ -859,7 +905,7 @@ class Module < Object
859
905
  # end
860
906
  # # => prints "A included in Enumerable"
861
907
  #
862
- def included: (Module othermod) -> untyped
908
+ private def included: (Module othermod) -> untyped
863
909
 
864
910
  # <!--
865
911
  # rdoc-file=object.c
@@ -937,7 +983,7 @@ class Module < Object
937
983
  # interpreter = Interpreter.new
938
984
  # interpreter.interpret('dave')
939
985
  #
940
- # *produces:*
986
+ # <em>produces:</em>
941
987
  #
942
988
  # Hello there, Dave!
943
989
  #
@@ -994,11 +1040,11 @@ class Module < Object
994
1040
  # def some_instance_method() end
995
1041
  # end
996
1042
  #
997
- # *produces:*
1043
+ # <em>produces:</em>
998
1044
  #
999
1045
  # Adding :some_instance_method
1000
1046
  #
1001
- def method_added: (Symbol meth) -> untyped
1047
+ private def method_added: (Symbol meth) -> untyped
1002
1048
 
1003
1049
  # <!--
1004
1050
  # rdoc-file=vm_method.c
@@ -1055,11 +1101,36 @@ class Module < Object
1055
1101
  # remove_method :some_instance_method
1056
1102
  # end
1057
1103
  #
1058
- # *produces:*
1104
+ # <em>produces:</em>
1059
1105
  #
1060
1106
  # Removing :some_instance_method
1061
1107
  #
1062
- def method_removed: (Symbol method_name) -> untyped
1108
+ private def method_removed: (Symbol method_name) -> untyped
1109
+
1110
+ # <!--
1111
+ # rdoc-file=object.c
1112
+ # - method_undefined(method_name)
1113
+ # -->
1114
+ # Invoked as a callback whenever an instance method is undefined from the
1115
+ # receiver.
1116
+ #
1117
+ # module Chatty
1118
+ # def self.method_undefined(method_name)
1119
+ # puts "Undefining #{method_name.inspect}"
1120
+ # end
1121
+ # def self.some_class_method() end
1122
+ # def some_instance_method() end
1123
+ # class << self
1124
+ # undef_method :some_class_method
1125
+ # end
1126
+ # undef_method :some_instance_method
1127
+ # end
1128
+ #
1129
+ # <em>produces:</em>
1130
+ #
1131
+ # Undefining :some_instance_method
1132
+ #
1133
+ private def method_undefined: (Symbol method_name) -> untyped
1063
1134
 
1064
1135
  # <!--
1065
1136
  # rdoc-file=vm_eval.c
@@ -1081,7 +1152,7 @@ class Module < Object
1081
1152
  # puts Thing.new.hello()
1082
1153
  # Thing.module_eval("invalid code", "dummy", 123)
1083
1154
  #
1084
- # *produces:*
1155
+ # <em>produces:</em>
1085
1156
  #
1086
1157
  # Hello there!
1087
1158
  # dummy:123:in `module_eval': undefined local variable
@@ -1107,7 +1178,7 @@ class Module < Object
1107
1178
  # }
1108
1179
  # puts Thing.new.hello()
1109
1180
  #
1110
- # *produces:*
1181
+ # <em>produces:</em>
1111
1182
  #
1112
1183
  # Hello there!
1113
1184
  #
@@ -1152,11 +1223,11 @@ class Module < Object
1152
1223
  # Mod.one #=> "This is one"
1153
1224
  # c.call_one #=> "This is the new one"
1154
1225
  #
1155
- def module_function: () -> nil
1156
- | (Symbol method_name) -> Symbol
1157
- | (Symbol, Symbol, *Symbol method_name) -> Array[Symbol]
1158
- | (string method_name) -> string
1159
- | (interned, interned, *interned method_name) -> Array[interned]
1226
+ private def module_function: () -> nil
1227
+ | (Symbol method_name) -> Symbol
1228
+ | (Symbol, Symbol, *Symbol method_name) -> Array[Symbol]
1229
+ | (string method_name) -> string
1230
+ | (interned, interned, *interned method_name) -> Array[interned]
1160
1231
 
1161
1232
  # <!--
1162
1233
  # rdoc-file=object.c
@@ -1184,7 +1255,7 @@ class Module < Object
1184
1255
  # this module to *mod* if this module has not already been added to *mod* or one
1185
1256
  # of its ancestors. See also Module#prepend.
1186
1257
  #
1187
- def prepend_features: (Module arg0) -> self
1258
+ private def prepend_features: (Module arg0) -> self
1188
1259
 
1189
1260
  # <!--
1190
1261
  # rdoc-file=object.c
@@ -1202,7 +1273,7 @@ class Module < Object
1202
1273
  # end
1203
1274
  # # => prints "A prepended to Enumerable"
1204
1275
  #
1205
- def prepended: (Module othermod) -> untyped
1276
+ private def prepended: (Module othermod) -> untyped
1206
1277
 
1207
1278
  # <!--
1208
1279
  # rdoc-file=vm_method.c
@@ -1227,14 +1298,14 @@ class Module < Object
1227
1298
  # end
1228
1299
  # Mod.private_instance_methods #=> [:a, :c]
1229
1300
  #
1230
- # Note that to show a private method on RDoc, use `:doc:`.
1301
+ # Note that to show a private method on RDoc, use <code>:doc:</code>.
1231
1302
  #
1232
- def private: () -> nil
1233
- | (Symbol method_name) -> Symbol
1234
- | (Symbol, Symbol, *Symbol method_name) -> Array[Symbol]
1235
- | (string method_name) -> string
1236
- | (interned, interned, *interned method_name) -> Array[interned]
1237
- | (Array[interned]) -> Array[interned]
1303
+ private def private: () -> nil
1304
+ | (Symbol method_name) -> Symbol
1305
+ | (Symbol, Symbol, *Symbol method_name) -> Array[Symbol]
1306
+ | (string method_name) -> string
1307
+ | (interned, interned, *interned method_name) -> Array[interned]
1308
+ | (Array[interned]) -> Array[interned]
1238
1309
 
1239
1310
  # <!--
1240
1311
  # rdoc-file=vm_method.c
@@ -1321,28 +1392,61 @@ class Module < Object
1321
1392
  # - protected(method_name, method_name, ...) -> array
1322
1393
  # - protected(array) -> array
1323
1394
  # -->
1324
- # With no arguments, sets the default visibility for subsequently defined
1325
- # methods to protected. With arguments, sets the named methods to have protected
1326
- # visibility. String arguments are converted to symbols. An Array of Symbols
1327
- # and/or Strings is also accepted. If a single argument is passed, it is
1328
- # returned. If no argument is passed, nil is returned. If multiple arguments are
1329
- # passed, the arguments are returned as an array.
1395
+ # Sets the visibility of a section or of a list of method names as protected.
1396
+ # Accepts no arguments, a splat of method names (symbols or strings) or an array
1397
+ # of method names. Returns the arguments that it received.
1398
+ #
1399
+ # ## Important difference between protected in other languages
1400
+ #
1401
+ # Protected methods in Ruby are different from other languages such as Java,
1402
+ # where methods are marked as protected to give access to subclasses. In Ruby,
1403
+ # subclasses **already have access to all methods defined in the parent class**,
1404
+ # even private ones.
1405
+ #
1406
+ # Marking a method as protected allows **different objects of the same class**
1407
+ # to call it.
1408
+ #
1409
+ # One use case is for comparison methods, such as <code>==</code>, if we want to
1410
+ # expose a method for comparison between objects of the same class without
1411
+ # making the method public to objects of other classes.
1412
+ #
1413
+ # ## Performance considerations
1330
1414
  #
1331
- # If a method has protected visibility, it is callable only where `self` of the
1332
- # context is the same as the method. (method definition or instance_eval). This
1333
- # behavior is different from Java's protected method. Usually `private` should
1334
- # be used.
1415
+ # Protected methods are slower than others because they can't use inline cache.
1335
1416
  #
1336
- # Note that a protected method is slow because it can't use inline cache.
1417
+ # ## Example
1337
1418
  #
1338
- # To show a private method on RDoc, use `:doc:` instead of this.
1419
+ # class Account
1420
+ # # Mark balance as protected, so that we can compare between accounts
1421
+ # # without making it public.
1422
+ # attr_reader :balance
1423
+ # protected :balance
1339
1424
  #
1340
- def protected: () -> nil
1341
- | (Symbol method_name) -> Symbol
1342
- | (Symbol, Symbol, *Symbol method_name) -> Array[Symbol]
1343
- | (string method_name) -> string
1344
- | (interned, interned, *interned method_name) -> Array[interned]
1345
- | (Array[interned]) -> Array[interned]
1425
+ # def initialize(balance)
1426
+ # @balance = balance
1427
+ # end
1428
+ #
1429
+ # def >(other)
1430
+ # # The invocation to `other.balance` is allowed because `other` is a
1431
+ # # different object of the same class (Account).
1432
+ # balance > other.balance
1433
+ # end
1434
+ # end
1435
+ #
1436
+ # account1 = Account.new(100)
1437
+ # account2 = Account.new(50)
1438
+ #
1439
+ # account1 > account2 # => true (works)
1440
+ # account1.balance # => NoMethodError (fails because balance is not public)
1441
+ #
1442
+ # To show a private method on RDoc, use <code>:doc:</code> instead of this.
1443
+ #
1444
+ private def protected: () -> nil
1445
+ | (Symbol method_name) -> Symbol
1446
+ | (Symbol, Symbol, *Symbol method_name) -> Array[Symbol]
1447
+ | (string method_name) -> string
1448
+ | (interned, interned, *interned method_name) -> Array[interned]
1449
+ | (Array[interned]) -> Array[interned]
1346
1450
 
1347
1451
  # <!--
1348
1452
  # rdoc-file=object.c
@@ -1397,12 +1501,12 @@ class Module < Object
1397
1501
  # returned. If no argument is passed, nil is returned. If multiple arguments are
1398
1502
  # passed, the arguments are returned as an array.
1399
1503
  #
1400
- def public: () -> nil
1401
- | (Symbol method_name) -> Symbol
1402
- | (Symbol, Symbol, *Symbol method_name) -> Array[Symbol]
1403
- | (string method_name) -> string
1404
- | (interned, interned, *interned method_name) -> Array[interned]
1405
- | (Array[interned]) -> Array[interned]
1504
+ private def public: () -> nil
1505
+ | (Symbol method_name) -> Symbol
1506
+ | (Symbol, Symbol, *Symbol method_name) -> Array[Symbol]
1507
+ | (string method_name) -> string
1508
+ | (interned, interned, *interned method_name) -> Array[interned]
1509
+ | (Array[interned]) -> Array[interned]
1406
1510
 
1407
1511
  # <!--
1408
1512
  # rdoc-file=vm_method.c
@@ -1481,7 +1585,7 @@ class Module < Object
1481
1585
  #
1482
1586
  # Returns a module, where refined methods are defined.
1483
1587
  #
1484
- def refine: (Module mod) { () [self: Refinement] -> void } -> Refinement
1588
+ private def refine: (Module mod) { () [self: Refinement] -> void } -> Refinement
1485
1589
 
1486
1590
  # <!--
1487
1591
  # rdoc-file=eval.c
@@ -1499,7 +1603,7 @@ class Module < Object
1499
1603
  #
1500
1604
  # p A.refinements
1501
1605
  #
1502
- # *produces:*
1606
+ # <em>produces:</em>
1503
1607
  #
1504
1608
  # [#<refinement:Integer@A>, #<refinement:String@A>]
1505
1609
  #
@@ -1518,7 +1622,7 @@ class Module < Object
1518
1622
  # p(defined? @@var)
1519
1623
  # end
1520
1624
  #
1521
- # *produces:*
1625
+ # <em>produces:</em>
1522
1626
  #
1523
1627
  # 99
1524
1628
  # nil
@@ -1533,7 +1637,7 @@ class Module < Object
1533
1637
  # previous value. If that constant referred to a module, this will not change
1534
1638
  # that module's name and can lead to confusion.
1535
1639
  #
1536
- def remove_const: (interned arg0) -> untyped
1640
+ private def remove_const: (interned arg0) -> untyped
1537
1641
 
1538
1642
  # <!--
1539
1643
  # rdoc-file=vm_method.c
@@ -1545,6 +1649,43 @@ class Module < Object
1545
1649
  #
1546
1650
  def remove_method: (*interned arg0) -> self
1547
1651
 
1652
+ # <!--
1653
+ # rdoc-file=vm_method.c
1654
+ # - ruby2_keywords(method_name, ...) -> nil
1655
+ # -->
1656
+ # For the given method names, marks the method as passing keywords through a
1657
+ # normal argument splat. This should only be called on methods that accept an
1658
+ # argument splat (<code>*args</code>) but not explicit keywords or a keyword
1659
+ # splat. It marks the method such that if the method is called with keyword
1660
+ # arguments, the final hash argument is marked with a special flag such that if
1661
+ # it is the final element of a normal argument splat to another method call, and
1662
+ # that method call does not include explicit keywords or a keyword splat, the
1663
+ # final element is interpreted as keywords. In other words, keywords will be
1664
+ # passed through the method to other methods.
1665
+ #
1666
+ # This should only be used for methods that delegate keywords to another method,
1667
+ # and only for backwards compatibility with Ruby versions before 3.0. See
1668
+ # https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyw
1669
+ # ord-arguments-in-ruby-3-0/ for details on why `ruby2_keywords` exists and when
1670
+ # and how to use it.
1671
+ #
1672
+ # This method will probably be removed at some point, as it exists only for
1673
+ # backwards compatibility. As it does not exist in Ruby versions before 2.7,
1674
+ # check that the module responds to this method before calling it:
1675
+ #
1676
+ # module Mod
1677
+ # def foo(meth, *args, &block)
1678
+ # send(:"do_#{meth}", *args, &block)
1679
+ # end
1680
+ # ruby2_keywords(:foo) if respond_to?(:ruby2_keywords, true)
1681
+ # end
1682
+ #
1683
+ # However, be aware that if the `ruby2_keywords` method is removed, the behavior
1684
+ # of the `foo` method using the above approach will change so that the method
1685
+ # does not pass through keywords.
1686
+ #
1687
+ private def ruby2_keywords: (*interned method_name) -> nil
1688
+
1548
1689
  # <!--
1549
1690
  # rdoc-file=object.c
1550
1691
  # - mod.set_temporary_name(string) -> self
@@ -1578,7 +1719,7 @@ class Module < Object
1578
1719
  # m.name #=> nil
1579
1720
  #
1580
1721
  # c = Class.new
1581
- # c.set_temporary_name("MyClass(with description)")
1722
+ # c.set_temporary_name("MyClass(with description)") # => MyClass(with description)
1582
1723
  #
1583
1724
  # c.new # => #<MyClass(with description):0x0....>
1584
1725
  #
@@ -1652,7 +1793,7 @@ class Module < Object
1652
1793
  # end
1653
1794
  # c.hello
1654
1795
  #
1655
- # *produces:*
1796
+ # <em>produces:</em>
1656
1797
  #
1657
1798
  # In child
1658
1799
  # In parent
@@ -1676,7 +1817,7 @@ class Module < Object
1676
1817
  # Import class refinements from *module* into the current class or module
1677
1818
  # definition.
1678
1819
  #
1679
- def using: (Module arg0) -> self
1820
+ private def using: (Module arg0) -> self
1680
1821
 
1681
1822
  # <!-- rdoc-file=object.c -->
1682
1823
  # Returns a string representing this module or class. For basic classes and
@@ -1692,13 +1833,10 @@ class Module < Object
1692
1833
  # - attr(name, false) -> array
1693
1834
  # -->
1694
1835
  # The first form is equivalent to #attr_reader. The second form is equivalent to
1695
- # `attr_accessor(name)` but deprecated. The last form is equivalent to
1696
- # `attr_reader(name)` but deprecated. Returns an array of defined method names
1697
- # as symbols.
1836
+ # <code>attr_accessor(name)</code> but deprecated. The last form is equivalent
1837
+ # to <code>attr_reader(name)</code> but deprecated. Returns an array of defined
1838
+ # method names as symbols.
1698
1839
  #
1699
- def attr: (*interned arg0) -> Array[Symbol]
1700
-
1701
- # A previous incarnation of `interned` for backward-compatibility (see #1499)
1702
- %a{deprecated: Use `interned`}
1703
- type id = interned
1840
+ def attr: %a{deprecated} (interned, bool) -> Array[Symbol]
1841
+ | (*interned arg0) -> Array[Symbol]
1704
1842
  end