rbs 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -0
  3. data/CHANGELOG.md +23 -0
  4. data/README.md +6 -1
  5. data/core/array.rbs +2866 -1086
  6. data/core/basic_object.rbs +150 -30
  7. data/core/binding.rbs +33 -0
  8. data/core/builtin.rbs +4 -4
  9. data/core/class.rbs +43 -5
  10. data/core/comparable.rbs +57 -0
  11. data/core/complex.rbs +170 -4
  12. data/core/constants.rbs +51 -0
  13. data/core/deprecated.rbs +7 -0
  14. data/core/dir.rbs +305 -20
  15. data/core/encoding.rbs +472 -77
  16. data/core/enumerable.rbs +2173 -234
  17. data/core/enumerator.rbs +448 -182
  18. data/core/env.rbs +448 -1
  19. data/core/errno.rbs +1 -10
  20. data/core/errors.rbs +152 -2
  21. data/core/exception.rbs +201 -127
  22. data/core/false_class.rbs +27 -0
  23. data/core/fiber.rbs +118 -37
  24. data/core/fiber_error.rbs +8 -9
  25. data/core/file.rbs +1059 -139
  26. data/core/file_test.rbs +287 -32
  27. data/core/float.rbs +776 -300
  28. data/core/gc.rbs +185 -34
  29. data/core/global_variables.rbs +5 -1
  30. data/core/hash.rbs +1582 -649
  31. data/core/integer.rbs +974 -204
  32. data/core/io/buffer.rbs +710 -0
  33. data/core/io/wait.rbs +29 -8
  34. data/core/io.rbs +2438 -417
  35. data/core/kernel.rbs +2315 -316
  36. data/core/marshal.rbs +37 -2
  37. data/core/match_data.rbs +123 -6
  38. data/core/math.rbs +126 -6
  39. data/core/method.rbs +226 -102
  40. data/core/module.rbs +421 -45
  41. data/core/nil_class.rbs +64 -0
  42. data/core/numeric.rbs +620 -142
  43. data/core/object.rbs +453 -81
  44. data/core/object_space.rbs +92 -2
  45. data/core/proc.rbs +482 -285
  46. data/core/process.rbs +443 -34
  47. data/core/ractor.rbs +232 -9
  48. data/core/random.rbs +151 -52
  49. data/core/range.rbs +885 -160
  50. data/core/rational.rbs +122 -6
  51. data/core/rb_config.rbs +14 -4
  52. data/core/refinement.rbs +44 -0
  53. data/core/regexp.rbs +156 -14
  54. data/core/ruby_vm.rbs +42 -3
  55. data/core/signal.rbs +78 -39
  56. data/core/string.rbs +2123 -567
  57. data/core/string_io.rbs +204 -0
  58. data/core/struct.rbs +283 -28
  59. data/core/symbol.rbs +304 -30
  60. data/core/thread.rbs +1288 -688
  61. data/core/thread_group.rbs +66 -10
  62. data/core/time.rbs +643 -217
  63. data/core/trace_point.rbs +100 -12
  64. data/core/true_class.rbs +24 -0
  65. data/core/unbound_method.rbs +73 -7
  66. data/core/warning.rbs +37 -12
  67. data/docs/CONTRIBUTING.md +40 -34
  68. data/docs/stdlib.md +3 -102
  69. data/lib/rbs/annotate/annotations.rb +197 -0
  70. data/lib/rbs/annotate/formatter.rb +80 -0
  71. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  72. data/lib/rbs/annotate/rdoc_source.rb +120 -0
  73. data/lib/rbs/annotate.rb +6 -0
  74. data/lib/rbs/cli.rb +45 -1
  75. data/lib/rbs/definition_builder.rb +5 -1
  76. data/lib/rbs/location_aux.rb +12 -0
  77. data/lib/rbs/prototype/rb.rb +12 -0
  78. data/lib/rbs/version.rb +1 -1
  79. data/sig/annotate/annotations.rbs +102 -0
  80. data/sig/annotate/formatter.rbs +24 -0
  81. data/sig/annotate/rdoc_annotater.rbs +82 -0
  82. data/sig/annotate/rdoc_source.rbs +30 -0
  83. data/sig/cli.rbs +2 -0
  84. data/sig/collection/{collections.rbs → sources.rbs} +0 -0
  85. data/sig/location.rbs +6 -0
  86. data/sig/method_types.rbs +5 -1
  87. data/sig/polyfill.rbs +78 -0
  88. data/stdlib/abbrev/0/abbrev.rbs +6 -0
  89. data/stdlib/abbrev/0/array.rbs +26 -0
  90. data/stdlib/base64/0/base64.rbs +31 -0
  91. data/stdlib/benchmark/0/benchmark.rbs +74 -3
  92. data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
  93. data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
  94. data/stdlib/cgi/0/core.rbs +59 -0
  95. data/stdlib/coverage/0/coverage.rbs +164 -2
  96. data/stdlib/csv/0/csv.rbs +2862 -398
  97. data/stdlib/date/0/date.rbs +483 -25
  98. data/stdlib/date/0/date_time.rbs +187 -12
  99. data/stdlib/dbm/0/dbm.rbs +152 -17
  100. data/stdlib/digest/0/digest.rbs +146 -0
  101. data/stdlib/erb/0/erb.rbs +65 -245
  102. data/stdlib/fiber/0/fiber.rbs +73 -91
  103. data/stdlib/fileutils/0/fileutils.rbs +301 -1
  104. data/stdlib/find/0/find.rbs +9 -0
  105. data/stdlib/forwardable/0/forwardable.rbs +65 -1
  106. data/stdlib/io-console/0/io-console.rbs +227 -15
  107. data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
  108. data/stdlib/json/0/json.rbs +1146 -144
  109. data/stdlib/logger/0/formatter.rbs +24 -0
  110. data/stdlib/logger/0/log_device.rbs +64 -0
  111. data/stdlib/logger/0/logger.rbs +165 -13
  112. data/stdlib/logger/0/period.rbs +10 -0
  113. data/stdlib/logger/0/severity.rbs +26 -0
  114. data/stdlib/monitor/0/monitor.rbs +163 -0
  115. data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
  116. data/stdlib/net-http/0/net-http.rbs +1492 -683
  117. data/stdlib/nkf/0/nkf.rbs +372 -0
  118. data/stdlib/objspace/0/objspace.rbs +149 -90
  119. data/stdlib/openssl/0/openssl.rbs +8108 -71
  120. data/stdlib/optparse/0/optparse.rbs +487 -19
  121. data/stdlib/pathname/0/pathname.rbs +425 -124
  122. data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
  123. data/stdlib/prime/0/integer-extension.rbs +20 -2
  124. data/stdlib/prime/0/prime.rbs +88 -21
  125. data/stdlib/pstore/0/pstore.rbs +102 -0
  126. data/stdlib/pty/0/pty.rbs +64 -14
  127. data/stdlib/resolv/0/resolv.rbs +420 -31
  128. data/stdlib/rubygems/0/basic_specification.rbs +4 -1
  129. data/stdlib/rubygems/0/config_file.rbs +33 -1
  130. data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
  131. data/stdlib/rubygems/0/installer.rbs +13 -1
  132. data/stdlib/rubygems/0/path_support.rbs +4 -1
  133. data/stdlib/rubygems/0/platform.rbs +5 -1
  134. data/stdlib/rubygems/0/request_set.rbs +44 -2
  135. data/stdlib/rubygems/0/requirement.rbs +65 -2
  136. data/stdlib/rubygems/0/rubygems.rbs +407 -0
  137. data/stdlib/rubygems/0/source_list.rbs +13 -0
  138. data/stdlib/rubygems/0/specification.rbs +21 -1
  139. data/stdlib/rubygems/0/stream_ui.rbs +3 -1
  140. data/stdlib/rubygems/0/uninstaller.rbs +8 -1
  141. data/stdlib/rubygems/0/version.rbs +60 -157
  142. data/stdlib/securerandom/0/securerandom.rbs +44 -0
  143. data/stdlib/set/0/set.rbs +420 -106
  144. data/stdlib/shellwords/0/shellwords.rbs +55 -77
  145. data/stdlib/singleton/0/singleton.rbs +20 -0
  146. data/stdlib/socket/0/addrinfo.rbs +210 -9
  147. data/stdlib/socket/0/basic_socket.rbs +103 -11
  148. data/stdlib/socket/0/ip_socket.rbs +31 -9
  149. data/stdlib/socket/0/socket.rbs +586 -38
  150. data/stdlib/socket/0/tcp_server.rbs +22 -2
  151. data/stdlib/socket/0/tcp_socket.rbs +12 -1
  152. data/stdlib/socket/0/udp_socket.rbs +25 -2
  153. data/stdlib/socket/0/unix_server.rbs +22 -2
  154. data/stdlib/socket/0/unix_socket.rbs +45 -5
  155. data/stdlib/strscan/0/string_scanner.rbs +210 -9
  156. data/stdlib/tempfile/0/tempfile.rbs +58 -10
  157. data/stdlib/time/0/time.rbs +208 -116
  158. data/stdlib/timeout/0/timeout.rbs +10 -0
  159. data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
  160. data/stdlib/tsort/0/cyclic.rbs +1 -0
  161. data/stdlib/tsort/0/interfaces.rbs +1 -0
  162. data/stdlib/tsort/0/tsort.rbs +42 -0
  163. data/stdlib/uri/0/common.rbs +57 -8
  164. data/stdlib/uri/0/file.rbs +55 -109
  165. data/stdlib/uri/0/ftp.rbs +6 -3
  166. data/stdlib/uri/0/generic.rbs +556 -327
  167. data/stdlib/uri/0/http.rbs +26 -115
  168. data/stdlib/uri/0/https.rbs +8 -102
  169. data/stdlib/uri/0/ldap.rbs +143 -137
  170. data/stdlib/uri/0/ldaps.rbs +8 -102
  171. data/stdlib/uri/0/mailto.rbs +3 -0
  172. data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
  173. data/stdlib/uri/0/ws.rbs +6 -3
  174. data/stdlib/uri/0/wss.rbs +5 -3
  175. data/stdlib/yaml/0/dbm.rbs +151 -87
  176. data/stdlib/yaml/0/store.rbs +6 -0
  177. data/stdlib/zlib/0/zlib.rbs +90 -31
  178. metadata +17 -5
  179. data/lib/rbs/location.rb +0 -221
data/core/exception.rbs CHANGED
@@ -1,195 +1,269 @@
1
- # Descendants of class [Exception](Exception) are used
2
- # to communicate between
3
- # [Kernel\#raise](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-raise)
4
- # and `rescue` statements in `begin ... end` blocks.
5
- # [Exception](Exception) objects carry information
6
- # about the exception – its type (the exception’s class name), an optional
7
- # descriptive string, and optional traceback information.
8
- # [Exception](Exception) subclasses may add additional
9
- # information like
10
- # [NameError\#name](https://ruby-doc.org/core-2.6.3/NameError.html#method-i-name)
11
- # .
12
- #
13
- # Programs may make subclasses of
14
- # [Exception](Exception), typically of
15
- # [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html) or
16
- # [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html), to
17
- # provide custom classes and add additional information. See the subclass
18
- # list below for defaults for `raise` and `rescue` .
19
- #
20
- # When an exception has been raised but not yet handled (in `rescue`,
21
- # `ensure`, `at_exit` and `END` blocks) the global variable `$!` will
22
- # contain the current exception and `$@` contains the current exception’s
23
- # backtrace.
24
- #
25
- # It is recommended that a library should have one subclass of
26
- # [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html) or
27
- # [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html) and
28
- # have specific exception types inherit from it. This allows the user to
29
- # rescue a generic exception type to catch all exceptions the library may
30
- # raise even if future versions of the library add new exception
31
- # subclasses.
1
+ # <!-- rdoc-file=error.c -->
2
+ # Class Exception and its subclasses are used to communicate between
3
+ # Kernel#raise and `rescue` statements in `begin ... end` blocks.
32
4
  #
33
- # For example:
34
- #
35
- # ```ruby
36
- # class MyLibrary
37
- # class Error < RuntimeError
38
- # end
39
- #
40
- # class WidgetError < Error
41
- # end
42
- #
43
- # class FrobError < Error
44
- # end
45
- #
46
- # end
47
- # ```
48
- #
49
- # To handle both WidgetError and FrobError the library user can rescue
50
- # MyLibrary::Error.
51
- #
52
- # The built-in subclasses of [Exception](Exception)
53
- # are:
54
- #
55
- # - [NoMemoryError](https://ruby-doc.org/core-2.6.3/NoMemoryError.html)
5
+ # An Exception object carries information about an exception:
6
+ # * Its type (the exception's class).
7
+ # * An optional descriptive message.
8
+ # * Optional backtrace information.
56
9
  #
57
- # - [ScriptError](https://ruby-doc.org/core-2.6.3/ScriptError.html)
58
10
  #
59
- # - [LoadError](https://ruby-doc.org/core-2.6.3/LoadError.html)
11
+ # Some built-in subclasses of Exception have additional methods: e.g.,
12
+ # NameError#name.
60
13
  #
61
- # - [NotImplementedError](https://ruby-doc.org/core-2.6.3/NotImplementedError.html)
14
+ # ## Defaults
62
15
  #
63
- # - [SyntaxError](https://ruby-doc.org/core-2.6.3/SyntaxError.html)
16
+ # Two Ruby statements have default exception classes:
17
+ # * `raise`: defaults to RuntimeError.
18
+ # * `rescue`: defaults to StandardError.
64
19
  #
65
- # - [SecurityError](https://ruby-doc.org/core-2.6.3/SecurityError.html)
66
20
  #
67
- # - [SignalException](https://ruby-doc.org/core-2.6.3/SignalException.html)
21
+ # ## Global Variables
68
22
  #
69
- # - [Interrupt](https://ruby-doc.org/core-2.6.3/Interrupt.html)
23
+ # When an exception has been raised but not yet handled (in `rescue`, `ensure`,
24
+ # `at_exit` and `END` blocks), two global variables are set:
25
+ # * `$!` contains the current exception.
26
+ # * `$@` contains its backtrace.
70
27
  #
71
- # - [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html)
72
- # -- default for `rescue`
73
28
  #
74
- # - [ArgumentError](https://ruby-doc.org/core-2.6.3/ArgumentError.html)
29
+ # ## Custom Exceptions
75
30
  #
76
- # - [UncaughtThrowError](https://ruby-doc.org/core-2.6.3/UncaughtThrowError.html)
31
+ # To provide additional or alternate information, a program may create custom
32
+ # exception classes that derive from the built-in exception classes.
77
33
  #
78
- # - [EncodingError](https://ruby-doc.org/core-2.6.3/EncodingError.html)
34
+ # A good practice is for a library to create a single "generic" exception class
35
+ # (typically a subclass of StandardError or RuntimeError) and have its other
36
+ # exception classes derive from that class. This allows the user to rescue the
37
+ # generic exception, thus catching all exceptions the library may raise even if
38
+ # future versions of the library add new exception subclasses.
79
39
  #
80
- # - [FiberError](https://ruby-doc.org/core-2.6.3/FiberError.html)
81
- #
82
- # - [IOError](https://ruby-doc.org/core-2.6.3/IOError.html)
40
+ # For example:
83
41
  #
84
- # - [EOFError](https://ruby-doc.org/core-2.6.3/EOFError.html)
42
+ # class MyLibrary
43
+ # class Error < ::StandardError
44
+ # end
85
45
  #
86
- # - [IndexError](https://ruby-doc.org/core-2.6.3/IndexError.html)
46
+ # class WidgetError < Error
47
+ # end
87
48
  #
88
- # - [KeyError](https://ruby-doc.org/core-2.6.3/KeyError.html)
49
+ # class FrobError < Error
50
+ # end
89
51
  #
90
- # - [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html)
52
+ # end
91
53
  #
92
- # - [LocalJumpError](https://ruby-doc.org/core-2.6.3/LocalJumpError.html)
54
+ # To handle both MyLibrary::WidgetError and MyLibrary::FrobError the library
55
+ # user can rescue MyLibrary::Error.
93
56
  #
94
- # - [NameError](https://ruby-doc.org/core-2.6.3/NameError.html)
57
+ # ## Built-In Exception Classes
95
58
  #
96
- # - [NoMethodError](https://ruby-doc.org/core-2.6.3/NoMethodError.html)
59
+ # The built-in subclasses of Exception are:
97
60
  #
98
- # - [RangeError](https://ruby-doc.org/core-2.6.3/RangeError.html)
61
+ # * NoMemoryError
62
+ # * ScriptError
63
+ # * LoadError
64
+ # * NotImplementedError
65
+ # * SyntaxError
99
66
  #
100
- # - [FloatDomainError](https://ruby-doc.org/core-2.6.3/FloatDomainError.html)
67
+ # * SecurityError
68
+ # * SignalException
69
+ # * Interrupt
101
70
  #
102
- # - [RegexpError](https://ruby-doc.org/core-2.6.3/RegexpError.html)
71
+ # * StandardError
72
+ # * ArgumentError
73
+ # * UncaughtThrowError
103
74
  #
104
- # - [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html)
105
- # -- default for `raise`
75
+ # * EncodingError
76
+ # * FiberError
77
+ # * IOError
78
+ # * EOFError
106
79
  #
107
- # - [FrozenError](https://ruby-doc.org/core-2.6.3/FrozenError.html)
80
+ # * IndexError
81
+ # * KeyError
82
+ # * StopIteration
83
+ # * ClosedQueueError
108
84
  #
109
- # - [SystemCallError](https://ruby-doc.org/core-2.6.3/SystemCallError.html)
110
85
  #
111
- # - Errno::\*
86
+ # * LocalJumpError
87
+ # * NameError
88
+ # * NoMethodError
112
89
  #
113
- # - [ThreadError](https://ruby-doc.org/core-2.6.3/ThreadError.html)
90
+ # * RangeError
91
+ # * FloatDomainError
114
92
  #
115
- # - [TypeError](https://ruby-doc.org/core-2.6.3/TypeError.html)
93
+ # * RegexpError
94
+ # * RuntimeError
95
+ # * FrozenError
116
96
  #
117
- # - [ZeroDivisionError](https://ruby-doc.org/core-2.6.3/ZeroDivisionError.html)
97
+ # * SystemCallError
98
+ # * Errno::*
118
99
  #
119
- # - [SystemExit](https://ruby-doc.org/core-2.6.3/SystemExit.html)
100
+ # * ThreadError
101
+ # * TypeError
102
+ # * ZeroDivisionError
120
103
  #
121
- # - [SystemStackError](https://ruby-doc.org/core-2.6.3/SystemStackError.html)
104
+ # * SystemExit
105
+ # * SystemStackError
106
+ # * fatal
122
107
  #
123
- # - fatal – impossible to rescue
124
108
  class Exception < Object
109
+ # <!--
110
+ # rdoc-file=error.c
111
+ # - Exception.to_tty? -> true or false
112
+ # -->
113
+ # Returns `true` if exception messages will be sent to a tty.
114
+ #
125
115
  def self.to_tty?: () -> bool
126
116
 
117
+ # <!--
118
+ # rdoc-file=error.c
119
+ # - exc.exception([string]) -> an_exception or exc
120
+ # -->
121
+ # With no argument, or if the argument is the same as the receiver, return the
122
+ # receiver. Otherwise, create a new exception object of the same class as the
123
+ # receiver, but with a message equal to `string.to_str`.
124
+ #
127
125
  def self.exception: (?String msg) -> Exception
128
126
 
127
+ # <!--
128
+ # rdoc-file=error.c
129
+ # - exc == obj -> true or false
130
+ # -->
131
+ # Equality---If *obj* is not an Exception, returns `false`. Otherwise, returns
132
+ # `true` if *exc* and *obj* share same class, messages, and backtrace.
133
+ #
129
134
  def ==: (untyped arg0) -> bool
130
135
 
131
- # Returns any backtrace associated with the exception. The backtrace is an
132
- # array of strings, each containing either “filename:lineNo: in \`method”‘
133
- # or “filename:lineNo.”
134
- #
135
- # ```ruby
136
- # def a
137
- # raise "boom"
138
- # end
139
- #
140
- # def b
141
- # a()
142
- # end
143
- #
144
- # begin
145
- # b()
146
- # rescue => detail
147
- # print detail.backtrace.join("\n")
148
- # end
149
- # ```
136
+ # <!--
137
+ # rdoc-file=error.c
138
+ # - exception.backtrace -> array or nil
139
+ # -->
140
+ # Returns any backtrace associated with the exception. The backtrace is an array
141
+ # of strings, each containing either ``filename:lineNo: in `method''' or
142
+ # ``filename:lineNo.''
143
+ #
144
+ # def a
145
+ # raise "boom"
146
+ # end
147
+ #
148
+ # def b
149
+ # a()
150
+ # end
151
+ #
152
+ # begin
153
+ # b()
154
+ # rescue => detail
155
+ # print detail.backtrace.join("\n")
156
+ # end
150
157
  #
151
158
  # *produces:*
152
159
  #
153
160
  # prog.rb:2:in `a'
154
161
  # prog.rb:6:in `b'
155
162
  # prog.rb:10
163
+ #
164
+ # In the case no backtrace has been set, `nil` is returned
165
+ #
166
+ # ex = StandardError.new
167
+ # ex.backtrace
168
+ # #=> nil
169
+ #
156
170
  def backtrace: () -> ::Array[String]?
157
171
 
158
- # Returns any backtrace associated with the exception. This method is
159
- # similar to
160
- # [\#backtrace](Exception.downloaded.ruby_doc#method-i-backtrace), but
161
- # the backtrace is an array of
162
- # [Thread::Backtrace::Location](https://ruby-doc.org/core-2.6.3/Thread/Backtrace/Location.html)
163
- # .
164
- #
165
- # Now, this method is not affected by
166
- # [\#set\_backtrace](Exception.downloaded.ruby_doc#method-i-set_backtrace)
167
- # .
172
+ # <!--
173
+ # rdoc-file=error.c
174
+ # - exception.backtrace_locations -> array or nil
175
+ # -->
176
+ # Returns any backtrace associated with the exception. This method is similar to
177
+ # Exception#backtrace, but the backtrace is an array of
178
+ # Thread::Backtrace::Location.
179
+ #
180
+ # This method is not affected by Exception#set_backtrace().
181
+ #
168
182
  def backtrace_locations: () -> ::Array[Thread::Backtrace::Location]?
169
183
 
170
- # Returns the previous exception ($\!) at the time this exception was
171
- # raised. This is useful for wrapping exceptions and retaining the
172
- # original exception information.
184
+ # <!--
185
+ # rdoc-file=error.c
186
+ # - exception.cause -> an_exception or nil
187
+ # -->
188
+ # Returns the previous exception ($!) at the time this exception was raised.
189
+ # This is useful for wrapping exceptions and retaining the original exception
190
+ # information.
191
+ #
173
192
  def cause: () -> Exception?
174
193
 
194
+ # <!--
195
+ # rdoc-file=error.c
196
+ # - exc.exception([string]) -> an_exception or exc
197
+ # -->
198
+ # With no argument, or if the argument is the same as the receiver, return the
199
+ # receiver. Otherwise, create a new exception object of the same class as the
200
+ # receiver, but with a message equal to `string.to_str`.
201
+ #
175
202
  def exception: () -> self
176
203
  | (String arg0) -> Exception
177
204
 
205
+ # <!--
206
+ # rdoc-file=error.c
207
+ # - Exception.new(msg = nil) -> exception
208
+ # - Exception.exception(msg = nil) -> exception
209
+ # -->
210
+ # Construct a new Exception object, optionally passing in a message.
211
+ #
178
212
  def initialize: (?String arg0) -> void
179
213
 
180
- # Return this exception’s class name and message.
214
+ # <!--
215
+ # rdoc-file=error.c
216
+ # - exception.inspect -> string
217
+ # -->
218
+ # Return this exception's class name and message.
219
+ #
181
220
  def inspect: () -> String
182
221
 
183
- # Returns the result of invoking `exception.to_s` . Normally this returns
184
- # the exception’s message or name.
222
+ # <!--
223
+ # rdoc-file=error.c
224
+ # - exception.message -> string
225
+ # -->
226
+ # Returns the result of invoking `exception.to_s`. Normally this returns the
227
+ # exception's message or name.
228
+ #
185
229
  def message: () -> String
186
230
 
231
+ # <!--
232
+ # rdoc-file=error.c
233
+ # - exc.set_backtrace(backtrace) -> array
234
+ # -->
235
+ # Sets the backtrace information associated with `exc`. The `backtrace` must be
236
+ # an array of String objects or a single String in the format described in
237
+ # Exception#backtrace.
238
+ #
187
239
  def set_backtrace: (String | ::Array[String] arg0) -> ::Array[String]
188
240
  | (nil) -> nil
189
241
 
190
- # Returns exception’s message (or the name of the exception if no message
191
- # is set).
242
+ # <!--
243
+ # rdoc-file=error.c
244
+ # - exception.to_s -> string
245
+ # -->
246
+ # Returns exception's message (or the name of the exception if no message is
247
+ # set).
248
+ #
192
249
  def to_s: () -> String
193
250
 
251
+ # <!--
252
+ # rdoc-file=error.c
253
+ # - exception.full_message(highlight: bool, order: [:top or :bottom]) -> string
254
+ # -->
255
+ # Returns formatted string of *exception*. The returned string is formatted
256
+ # using the same format that Ruby uses when printing an uncaught exceptions to
257
+ # stderr.
258
+ #
259
+ # If *highlight* is `true` the default error handler will send the messages to a
260
+ # tty.
261
+ #
262
+ # *order* must be either of `:top` or `:bottom`, and places the error message
263
+ # and the innermost backtrace come at the top or the bottom.
264
+ #
265
+ # The default values of these options depend on `$stderr` and its `tty?` at the
266
+ # timing of a call.
267
+ #
194
268
  def full_message: (?highlight: bool, ?order: :top | :bottom) -> String
195
269
  end
data/core/false_class.rbs CHANGED
@@ -1,3 +1,4 @@
1
+ # <!-- rdoc-file=object.c -->
1
2
  # The global value `false` is the only instance of class FalseClass and
2
3
  # represents a logically false value in boolean expressions. The class provides
3
4
  # operators allowing `false` to participate correctly in logical expressions.
@@ -7,11 +8,20 @@ class FalseClass
7
8
 
8
9
  def !: () -> true
9
10
 
11
+ # <!--
12
+ # rdoc-file=object.c
13
+ # - false & obj -> false
14
+ # - nil & obj -> false
15
+ # -->
10
16
  # And---Returns `false`. *obj* is always evaluated as it is the argument to a
11
17
  # method call---there is no short-circuit evaluation in this case.
12
18
  #
13
19
  def &: (untyped obj) -> false
14
20
 
21
+ # <!--
22
+ # rdoc-file=object.c
23
+ # - obj === other -> true or false
24
+ # -->
15
25
  # Case Equality -- For class Object, effectively the same as calling `#==`, but
16
26
  # typically overridden by descendants to provide meaningful semantics in `case`
17
27
  # statements.
@@ -19,6 +29,11 @@ class FalseClass
19
29
  def ===: (false) -> true
20
30
  | (untyped obj) -> bool
21
31
 
32
+ # <!--
33
+ # rdoc-file=object.c
34
+ # - false ^ obj -> true or false
35
+ # - nil ^ obj -> true or false
36
+ # -->
22
37
  # Exclusive Or---If *obj* is `nil` or `false`, returns `false`; otherwise,
23
38
  # returns `true`.
24
39
  #
@@ -26,12 +41,24 @@ class FalseClass
26
41
  | (false) -> false
27
42
  | (untyped obj) -> true
28
43
 
44
+ # <!-- rdoc-file=object.c -->
45
+ # The string representation of `false` is "false".
46
+ #
29
47
  alias inspect to_s
30
48
 
49
+ # <!--
50
+ # rdoc-file=object.c
51
+ # - false.to_s -> "false"
52
+ # -->
31
53
  # The string representation of `false` is "false".
32
54
  #
33
55
  def to_s: () -> "false"
34
56
 
57
+ # <!--
58
+ # rdoc-file=object.c
59
+ # - false | obj -> true or false
60
+ # - nil | obj -> true or false
61
+ # -->
35
62
  # Or---Returns `false` if *obj* is `nil` or `false`; `true` otherwise.
36
63
  #
37
64
  def |: (nil) -> false
data/core/fiber.rbs CHANGED
@@ -1,35 +1,33 @@
1
- # Fibers are primitives for implementing light weight cooperative
2
- # concurrency in Ruby. Basically they are a means of creating code blocks
3
- # that can be paused and resumed, much like threads. The main difference
4
- # is that they are never preempted and that the scheduling must be done by
5
- # the programmer and not the VM.
1
+ # <!-- rdoc-file=cont.c -->
2
+ # Fibers are primitives for implementing light weight cooperative concurrency in
3
+ # Ruby. Basically they are a means of creating code blocks that can be paused
4
+ # and resumed, much like threads. The main difference is that they are never
5
+ # preempted and that the scheduling must be done by the programmer and not the
6
+ # VM.
6
7
  #
7
- # As opposed to other stackless light weight concurrency models, each
8
- # fiber comes with a stack. This enables the fiber to be paused from
9
- # deeply nested function calls within the fiber block. See the ruby(1)
10
- # manpage to configure the size of the fiber stack(s).
8
+ # As opposed to other stackless light weight concurrency models, each fiber
9
+ # comes with a stack. This enables the fiber to be paused from deeply nested
10
+ # function calls within the fiber block. See the ruby(1) manpage to configure
11
+ # the size of the fiber stack(s).
11
12
  #
12
13
  # When a fiber is created it will not run automatically. Rather it must be
13
- # explicitly asked to run using the `Fiber#resume` method. The code
14
- # running inside the fiber can give up control by calling `Fiber.yield` in
15
- # which case it yields control back to caller (the caller of the
16
- # `Fiber#resume` ).
14
+ # explicitly asked to run using the Fiber#resume method. The code running inside
15
+ # the fiber can give up control by calling Fiber.yield in which case it yields
16
+ # control back to caller (the caller of the Fiber#resume).
17
17
  #
18
- # Upon yielding or termination the [Fiber](Fiber)
19
- # returns the value of the last executed expression
18
+ # Upon yielding or termination the Fiber returns the value of the last executed
19
+ # expression
20
20
  #
21
21
  # For instance:
22
22
  #
23
- # ```ruby
24
- # fiber = Fiber.new do
25
- # Fiber.yield 1
26
- # 2
27
- # end
23
+ # fiber = Fiber.new do
24
+ # Fiber.yield 1
25
+ # 2
26
+ # end
28
27
  #
29
- # puts fiber.resume
30
- # puts fiber.resume
31
- # puts fiber.resume
32
- # ```
28
+ # puts fiber.resume
29
+ # puts fiber.resume
30
+ # puts fiber.resume
33
31
  #
34
32
  # *produces*
35
33
  #
@@ -37,35 +35,118 @@
37
35
  # 2
38
36
  # FiberError: dead fiber called
39
37
  #
40
- # The `Fiber#resume` method accepts an arbitrary number of parameters, if
41
- # it is the first call to `resume` then they will be passed as block
42
- # arguments. Otherwise they will be the return value of the call to
43
- # `Fiber.yield`
38
+ # The Fiber#resume method accepts an arbitrary number of parameters, if it is
39
+ # the first call to #resume then they will be passed as block arguments.
40
+ # Otherwise they will be the return value of the call to Fiber.yield
44
41
  #
45
42
  # Example:
46
43
  #
47
- # ```ruby
48
- # fiber = Fiber.new do |first|
49
- # second = Fiber.yield first + 2
50
- # end
44
+ # fiber = Fiber.new do |first|
45
+ # second = Fiber.yield first + 2
46
+ # end
51
47
  #
52
- # puts fiber.resume 10
53
- # puts fiber.resume 14
54
- # puts fiber.resume 18
55
- # ```
48
+ # puts fiber.resume 10
49
+ # puts fiber.resume 1_000_000
50
+ # puts fiber.resume "The fiber will be dead before I can cause trouble"
56
51
  #
57
52
  # *produces*
58
53
  #
59
54
  # 12
60
- # 14
55
+ # 1000000
61
56
  # FiberError: dead fiber called
57
+ #
58
+ # ## Non-blocking Fibers
59
+ #
60
+ # The concept of *non-blocking fiber* was introduced in Ruby 3.0. A non-blocking
61
+ # fiber, when reaching a operation that would normally block the fiber (like
62
+ # `sleep`, or wait for another process or I/O) will yield control to other
63
+ # fibers and allow the *scheduler* to handle blocking and waking up (resuming)
64
+ # this fiber when it can proceed.
65
+ #
66
+ # For a Fiber to behave as non-blocking, it need to be created in Fiber.new with
67
+ # `blocking: false` (which is the default), and Fiber.scheduler should be set
68
+ # with Fiber.set_scheduler. If Fiber.scheduler is not set in the current thread,
69
+ # blocking and non-blocking fibers' behavior is identical.
70
+ #
71
+ # Ruby doesn't provide a scheduler class: it is expected to be implemented by
72
+ # the user and correspond to Fiber::SchedulerInterface.
73
+ #
74
+ # There is also Fiber.schedule method, which is expected to immediately perform
75
+ # the given block in a non-blocking manner. Its actual implementation is up to
76
+ # the scheduler.
77
+ #
62
78
  class Fiber < Object
79
+ # <!--
80
+ # rdoc-file=cont.c
81
+ # - Fiber.yield(args, ...) -> obj
82
+ # -->
83
+ # Yields control back to the context that resumed the fiber, passing along any
84
+ # arguments that were passed to it. The fiber will resume processing at this
85
+ # point when #resume is called next. Any arguments passed to the next #resume
86
+ # will be the value that this Fiber.yield expression evaluates to.
87
+ #
63
88
  def self.yield: (*untyped args) -> untyped
64
89
 
90
+ # <!--
91
+ # rdoc-file=cont.c
92
+ # - Fiber.new(blocking: false) { |*args| ... } -> fiber
93
+ # -->
94
+ # Creates new Fiber. Initially, the fiber is not running and can be resumed with
95
+ # #resume. Arguments to the first #resume call will be passed to the block:
96
+ #
97
+ # f = Fiber.new do |initial|
98
+ # current = initial
99
+ # loop do
100
+ # puts "current: #{current.inspect}"
101
+ # current = Fiber.yield
102
+ # end
103
+ # end
104
+ # f.resume(100) # prints: current: 100
105
+ # f.resume(1, 2, 3) # prints: current: [1, 2, 3]
106
+ # f.resume # prints: current: nil
107
+ # # ... and so on ...
108
+ #
109
+ # If `blocking: false` is passed to `Fiber.new`, *and* current thread has a
110
+ # Fiber.scheduler defined, the Fiber becomes non-blocking (see "Non-blocking
111
+ # Fibers" section in class docs).
112
+ #
65
113
  def initialize: () { () -> untyped } -> void
66
114
 
115
+ # <!--
116
+ # rdoc-file=cont.c
117
+ # - fiber.resume(args, ...) -> obj
118
+ # -->
119
+ # Resumes the fiber from the point at which the last Fiber.yield was called, or
120
+ # starts running it if it is the first call to #resume. Arguments passed to
121
+ # resume will be the value of the Fiber.yield expression or will be passed as
122
+ # block parameters to the fiber's block if this is the first #resume.
123
+ #
124
+ # Alternatively, when resume is called it evaluates to the arguments passed to
125
+ # the next Fiber.yield statement inside the fiber's block or to the block value
126
+ # if it runs to completion without any Fiber.yield
127
+ #
67
128
  def resume: (*untyped args) -> untyped
68
129
 
130
+ # <!--
131
+ # rdoc-file=cont.c
132
+ # - fiber.raise -> obj
133
+ # - fiber.raise(string) -> obj
134
+ # - fiber.raise(exception [, string [, array]]) -> obj
135
+ # -->
136
+ # Raises an exception in the fiber at the point at which the last `Fiber.yield`
137
+ # was called. If the fiber has not been started or has already run to
138
+ # completion, raises `FiberError`. If the fiber is yielding, it is resumed. If
139
+ # it is transferring, it is transferred into. But if it is resuming, raises
140
+ # `FiberError`.
141
+ #
142
+ # With no arguments, raises a `RuntimeError`. With a single `String` argument,
143
+ # raises a `RuntimeError` with the string as a message. Otherwise, the first
144
+ # parameter should be the name of an `Exception` class (or an object that
145
+ # returns an `Exception` object when sent an `exception` message). The optional
146
+ # second parameter sets the message associated with the exception, and the third
147
+ # parameter is an array of callback information. Exceptions are caught by the
148
+ # `rescue` clause of `begin...end` blocks.
149
+ #
69
150
  def raise: () -> untyped
70
151
  | (string message) -> untyped
71
152
  | (_Exception exception, ?string message, ?Array[String] backtrace) -> untyped
data/core/fiber_error.rbs CHANGED
@@ -1,12 +1,11 @@
1
- # Raised when an invalid operation is attempted on a
2
- # [Fiber](https://ruby-doc.org/core-2.6.3/Fiber.html), in particular when
3
- # attempting to call/resume a dead fiber, attempting to yield from the
4
- # root fiber, or calling a fiber across threads.
1
+ # <!-- rdoc-file=cont.c -->
2
+ # Raised when an invalid operation is attempted on a Fiber, in particular when
3
+ # attempting to call/resume a dead fiber, attempting to yield from the root
4
+ # fiber, or calling a fiber across threads.
5
+ #
6
+ # fiber = Fiber.new{}
7
+ # fiber.resume #=> nil
8
+ # fiber.resume #=> FiberError: dead fiber called
5
9
  #
6
- # ```ruby
7
- # fiber = Fiber.new{}
8
- # fiber.resume #=> nil
9
- # fiber.resume #=> FiberError: dead fiber called
10
- # ```
11
10
  class FiberError < StandardError
12
11
  end