rbs 3.7.0 → 3.8.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +7 -7
  4. data/CHANGELOG.md +52 -0
  5. data/core/array.rbs +1743 -1580
  6. data/core/basic_object.rbs +38 -35
  7. data/core/comparable.rbs +1 -1
  8. data/core/complex.rbs +165 -93
  9. data/core/data.rbs +1 -1
  10. data/core/dir.rbs +1 -17
  11. data/core/encoding.rbs +12 -6
  12. data/core/enumerable.rbs +270 -266
  13. data/core/enumerator.rbs +0 -2
  14. data/core/env.rbs +1 -1
  15. data/core/errno.rbs +33 -16
  16. data/core/errors.rbs +2 -2
  17. data/core/exception.rbs +236 -170
  18. data/core/fiber.rbs +3 -2
  19. data/core/file.rbs +32 -74
  20. data/core/float.rbs +125 -72
  21. data/core/gc.rbs +138 -40
  22. data/core/hash.rbs +120 -141
  23. data/core/integer.rbs +79 -50
  24. data/core/io/buffer.rbs +49 -43
  25. data/core/io.rbs +97 -144
  26. data/core/kernel.rbs +290 -200
  27. data/core/match_data.rbs +76 -2
  28. data/core/math.rbs +0 -36
  29. data/core/module.rbs +28 -23
  30. data/core/nil_class.rbs +0 -3
  31. data/core/numeric.rbs +100 -103
  32. data/core/object.rbs +0 -4
  33. data/core/object_space/weak_key_map.rbs +3 -4
  34. data/core/object_space.rbs +3 -3
  35. data/core/proc.rbs +0 -2
  36. data/core/process.rbs +109 -57
  37. data/core/ractor.rbs +37 -4
  38. data/core/range.rbs +114 -87
  39. data/core/rational.rbs +0 -2
  40. data/core/rbs/unnamed/argf.rbs +234 -33
  41. data/core/rbs/unnamed/env_class.rbs +35 -53
  42. data/core/rbs/unnamed/random.rbs +1 -2
  43. data/core/regexp.rbs +4 -52
  44. data/core/ruby_vm.rbs +88 -9
  45. data/core/rubygems/config_file.rbs +3 -0
  46. data/core/rubygems/errors.rbs +0 -5
  47. data/core/rubygems/platform.rbs +0 -9
  48. data/core/rubygems/rubygems.rbs +0 -5
  49. data/core/rubygems/version.rbs +6 -6
  50. data/core/set.rbs +3 -15
  51. data/core/string.rbs +130 -136
  52. data/core/struct.rbs +6 -18
  53. data/core/symbol.rbs +14 -21
  54. data/core/thread.rbs +32 -35
  55. data/core/time.rbs +127 -50
  56. data/core/trace_point.rbs +16 -0
  57. data/core/true_class.rbs +0 -1
  58. data/core/warning.rbs +9 -2
  59. data/docs/architecture.md +1 -1
  60. data/docs/syntax.md +1 -1
  61. data/ext/rbs_extension/location.c +29 -19
  62. data/ext/rbs_extension/parser.c +267 -292
  63. data/ext/rbs_extension/parserstate.c +56 -22
  64. data/lib/rbs/annotate/annotations.rb +3 -3
  65. data/lib/rbs/annotate/rdoc_source.rb +2 -2
  66. data/lib/rbs/cli/diff.rb +3 -3
  67. data/lib/rbs/cli/validate.rb +1 -1
  68. data/lib/rbs/cli.rb +13 -13
  69. data/lib/rbs/collection/config.rb +3 -1
  70. data/lib/rbs/definition_builder/ancestor_builder.rb +3 -3
  71. data/lib/rbs/environment_loader.rb +1 -1
  72. data/lib/rbs/namespace.rb +1 -0
  73. data/lib/rbs/parser_aux.rb +2 -2
  74. data/lib/rbs/prototype/rb.rb +11 -8
  75. data/lib/rbs/prototype/rbi.rb +9 -5
  76. data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
  77. data/lib/rbs/prototype/runtime.rb +4 -5
  78. data/lib/rbs/type_name.rb +14 -9
  79. data/lib/rbs/unit_test/type_assertions.rb +2 -2
  80. data/lib/rbs/validator.rb +3 -1
  81. data/lib/rbs/version.rb +1 -1
  82. data/lib/rdoc_plugin/parser.rb +2 -2
  83. data/rbs.gemspec +4 -0
  84. data/sig/ancestor_graph.rbs +4 -4
  85. data/sig/namespace.rbs +2 -3
  86. data/sig/resolver/constant_resolver.rbs +2 -2
  87. data/sig/resolver/context.rbs +1 -1
  88. data/sig/type_alias_regularity.rbs +5 -5
  89. data/sig/typename.rbs +8 -5
  90. data/sig/use_map.rbs +1 -1
  91. data/sig/validator.rbs +2 -2
  92. data/stdlib/base64/0/base64.rbs +0 -9
  93. data/stdlib/benchmark/0/benchmark.rbs +11 -2
  94. data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
  95. data/stdlib/cgi/0/core.rbs +47 -0
  96. data/stdlib/coverage/0/coverage.rbs +0 -3
  97. data/stdlib/csv/0/csv.rbs +18 -58
  98. data/stdlib/date/0/date.rbs +4 -19
  99. data/stdlib/did_you_mean/0/did_you_mean.rbs +0 -5
  100. data/stdlib/digest/0/digest.rbs +25 -2
  101. data/stdlib/erb/0/erb.rbs +0 -1
  102. data/stdlib/etc/0/etc.rbs +51 -34
  103. data/stdlib/fileutils/0/fileutils.rbs +3 -44
  104. data/stdlib/io-console/0/io-console.rbs +69 -15
  105. data/stdlib/ipaddr/0/ipaddr.rbs +8 -4
  106. data/stdlib/json/0/json.rbs +56 -71
  107. data/stdlib/logger/0/log_device.rbs +1 -1
  108. data/stdlib/logger/0/logger.rbs +3 -18
  109. data/stdlib/net-http/0/net-http.rbs +19 -77
  110. data/stdlib/nkf/0/nkf.rbs +30 -0
  111. data/stdlib/objspace/0/objspace.rbs +1 -2
  112. data/stdlib/observable/0/observable.rbs +1 -1
  113. data/stdlib/open-uri/0/open-uri.rbs +52 -0
  114. data/stdlib/open3/0/open3.rbs +0 -8
  115. data/stdlib/openssl/0/openssl.rbs +136 -69
  116. data/stdlib/optparse/0/optparse.rbs +58 -18
  117. data/stdlib/pathname/0/pathname.rbs +2 -8
  118. data/stdlib/pp/0/pp.rbs +3 -1
  119. data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
  120. data/stdlib/pstore/0/pstore.rbs +0 -6
  121. data/stdlib/psych/0/psych.rbs +15 -4
  122. data/stdlib/pty/0/pty.rbs +46 -4
  123. data/stdlib/rdoc/0/code_object.rbs +0 -4
  124. data/stdlib/rdoc/0/markup.rbs +10 -12
  125. data/stdlib/rdoc/0/rdoc.rbs +1 -2
  126. data/stdlib/resolv/0/resolv.rbs +8 -3
  127. data/stdlib/ripper/0/ripper.rbs +0 -2
  128. data/stdlib/securerandom/0/securerandom.rbs +0 -2
  129. data/stdlib/shellwords/0/shellwords.rbs +11 -12
  130. data/stdlib/singleton/0/singleton.rbs +0 -1
  131. data/stdlib/socket/0/addrinfo.rbs +0 -1
  132. data/stdlib/socket/0/basic_socket.rbs +0 -5
  133. data/stdlib/socket/0/socket.rbs +49 -25
  134. data/stdlib/socket/0/tcp_server.rbs +0 -3
  135. data/stdlib/socket/0/tcp_socket.rbs +58 -3
  136. data/stdlib/socket/0/udp_socket.rbs +0 -1
  137. data/stdlib/socket/0/unix_server.rbs +0 -3
  138. data/stdlib/strscan/0/string_scanner.rbs +1265 -422
  139. data/stdlib/tempfile/0/tempfile.rbs +135 -28
  140. data/stdlib/time/0/time.rbs +48 -35
  141. data/stdlib/timeout/0/timeout.rbs +11 -8
  142. data/stdlib/tmpdir/0/tmpdir.rbs +8 -1
  143. data/stdlib/tsort/0/tsort.rbs +0 -4
  144. data/stdlib/uri/0/common.rbs +11 -30
  145. data/stdlib/uri/0/ftp.rbs +1 -1
  146. data/stdlib/uri/0/generic.rbs +22 -18
  147. data/stdlib/uri/0/http.rbs +2 -2
  148. data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
  149. data/stdlib/zlib/0/buf_error.rbs +1 -70
  150. data/stdlib/zlib/0/data_error.rbs +1 -70
  151. data/stdlib/zlib/0/deflate.rbs +8 -72
  152. data/stdlib/zlib/0/error.rbs +1 -70
  153. data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
  154. data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
  155. data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
  156. data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
  157. data/stdlib/zlib/0/gzip_file.rbs +1 -71
  158. data/stdlib/zlib/0/gzip_reader.rbs +3 -74
  159. data/stdlib/zlib/0/gzip_writer.rbs +1 -70
  160. data/stdlib/zlib/0/inflate.rbs +4 -71
  161. data/stdlib/zlib/0/mem_error.rbs +1 -70
  162. data/stdlib/zlib/0/need_dict.rbs +1 -70
  163. data/stdlib/zlib/0/stream_end.rbs +1 -70
  164. data/stdlib/zlib/0/stream_error.rbs +1 -70
  165. data/stdlib/zlib/0/version_error.rbs +1 -70
  166. data/stdlib/zlib/0/zlib.rbs +0 -2
  167. data/stdlib/zlib/0/zstream.rbs +4 -72
  168. metadata +4 -6
data/core/enumerator.rbs CHANGED
@@ -6,7 +6,6 @@
6
6
  # * Object#enum_for
7
7
  # * Enumerator.new
8
8
  #
9
- #
10
9
  # Most methods have two forms: a block form where the contents are evaluated for
11
10
  # each item in the enumeration, and a non-block form which returns a new
12
11
  # Enumerator wrapping the iteration.
@@ -75,7 +74,6 @@
75
74
  # Enumerator Fiber, you need to use an extra indirection (e.g., use some
76
75
  # object in the Fiber storage variable and mutate some ivar of it).
77
76
  #
78
- #
79
77
  # Concretely:
80
78
  #
81
79
  # Thread.current[:fiber_local] = 1
data/core/env.rbs CHANGED
@@ -1,5 +1,5 @@
1
1
  # <!-- rdoc-file=hash.c -->
2
- # ENV is a Hash-like accessor for environment variables.
2
+ # `ENV` is a Hash-like accessor for environment variables.
3
3
  #
4
4
  # See ENV (the class) for more details.
5
5
  #
data/core/errno.rbs CHANGED
@@ -1,25 +1,42 @@
1
1
  # <!-- rdoc-file=error.c -->
2
- # Ruby exception objects are subclasses of Exception. However, operating
3
- # systems typically report errors using plain integers. Module Errno is created
4
- # dynamically to map these operating system errors to Ruby classes, with each
5
- # error number generating its own subclass of SystemCallError. As the subclass
6
- # is created in module Errno, its name will start `Errno::`.
2
+ # When an operating system encounters an error, it typically reports the error
3
+ # as an integer error code:
7
4
  #
8
- # The names of the `Errno::` classes depend on the environment in which Ruby
9
- # runs. On a typical Unix or Windows platform, there are Errno classes such as
10
- # Errno::EACCES, Errno::EAGAIN, Errno::EINTR, and so on.
5
+ # $ ls nosuch.txt
6
+ # ls: cannot access 'nosuch.txt': No such file or directory
7
+ # $ echo $? # Code for last error.
8
+ # 2
11
9
  #
12
- # The integer operating system error number corresponding to a particular error
13
- # is available as the class constant `Errno::`*error*`::Errno`.
10
+ # When the Ruby interpreter interacts with the operating system and receives
11
+ # such an error code (e.g., `2`), it maps the code to a particular Ruby
12
+ # exception class (e.g., `Errno::ENOENT`):
14
13
  #
15
- # Errno::EACCES::Errno #=> 13
16
- # Errno::EAGAIN::Errno #=> 11
17
- # Errno::EINTR::Errno #=> 4
14
+ # File.open('nosuch.txt')
15
+ # # => No such file or directory @ rb_sysopen - nosuch.txt (Errno::ENOENT)
18
16
  #
19
- # The full list of operating system errors on your particular platform are
20
- # available as the constants of Errno.
17
+ # Each such class is:
21
18
  #
22
- # Errno.constants #=> :E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, ...
19
+ # * A nested class in this module, `Errno`.
20
+ # * A subclass of class SystemCallError.
21
+ # * Associated with an error code.
22
+ #
23
+ # Thus:
24
+ #
25
+ # Errno::ENOENT.superclass # => SystemCallError
26
+ # Errno::ENOENT::Errno # => 2
27
+ #
28
+ # The names of nested classes are returned by method `Errno.constants`:
29
+ #
30
+ # Errno.constants.size # => 158
31
+ # Errno.constants.sort.take(5) # => [:E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, :EADV]
32
+ #
33
+ # As seen above, the error code associated with each class is available as the
34
+ # value of a constant; the value for a particular class may vary among operating
35
+ # systems. If the class is not needed for the particular operating system, the
36
+ # value is zero:
37
+ #
38
+ # Errno::ENOENT::Errno # => 2
39
+ # Errno::ENOTCAPABLE::Errno # => 0
23
40
  #
24
41
  module Errno
25
42
  class NOERROR < SystemCallError
data/core/errors.rbs CHANGED
@@ -190,7 +190,7 @@ end
190
190
  #
191
191
  class LoadError < ScriptError
192
192
  # <!-- rdoc-file=error.c -->
193
- # the path failed to load
193
+ # the path that failed to load
194
194
  #
195
195
  def path: () -> String?
196
196
  end
@@ -564,7 +564,7 @@ class SyntaxError < ScriptError
564
564
  def initialize: (?string msg) -> void
565
565
 
566
566
  # <!-- rdoc-file=error.c -->
567
- # the path failed to parse
567
+ # the path that failed to parse
568
568
  #
569
569
  def path: () -> String?
570
570
  end
data/core/exception.rbs CHANGED
@@ -1,310 +1,376 @@
1
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.
2
+ # Class `Exception` and its subclasses are used to indicate that an error or
3
+ # other problem has occurred, and may need to be handled. See
4
+ # [Exceptions](rdoc-ref:exceptions.md).
4
5
  #
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.
6
+ # An `Exception` object carries certain information:
9
7
  #
8
+ # * The type (the exception's class), commonly StandardError, RuntimeError, or
9
+ # a subclass of one or the other; see [Built-In Exception Class
10
+ # Hierarchy](rdoc-ref:Exception@Built-In+Exception+Class+Hierarchy).
11
+ # * An optional descriptive message; see methods ::new, #message.
12
+ # * Optional backtrace information; see methods #backtrace,
13
+ # #backtrace_locations, #set_backtrace.
14
+ # * An optional cause; see method #cause.
10
15
  #
11
- # Some built-in subclasses of Exception have additional methods: e.g.,
12
- # NameError#name.
16
+ # ## Built-In Exception Class Hierarchy
13
17
  #
14
- # ## Defaults
15
- #
16
- # Two Ruby statements have default exception classes:
17
- # * `raise`: defaults to RuntimeError.
18
- # * `rescue`: defaults to StandardError.
19
- #
20
- #
21
- # ## Global Variables
22
- #
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.
27
- #
28
- #
29
- # ## Custom Exceptions
30
- #
31
- # To provide additional or alternate information, a program may create custom
32
- # exception classes that derive from the built-in exception classes.
33
- #
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.
39
- #
40
- # For example:
41
- #
42
- # class MyLibrary
43
- # class Error < ::StandardError
44
- # end
45
- #
46
- # class WidgetError < Error
47
- # end
48
- #
49
- # class FrobError < Error
50
- # end
51
- #
52
- # end
53
- #
54
- # To handle both MyLibrary::WidgetError and MyLibrary::FrobError the library
55
- # user can rescue MyLibrary::Error.
56
- #
57
- # ## Built-In Exception Classes
58
- #
59
- # The built-in subclasses of Exception are:
18
+ # The hierarchy of built-in subclasses of class `Exception`:
60
19
  #
61
20
  # * NoMemoryError
62
21
  # * ScriptError
63
- # * LoadError
22
+ # * [LoadError](https://docs.ruby-lang.org/en/master/LoadError.html)
64
23
  # * NotImplementedError
65
24
  # * SyntaxError
66
- #
67
25
  # * SecurityError
68
26
  # * SignalException
69
27
  # * Interrupt
70
- #
71
28
  # * StandardError
72
29
  # * ArgumentError
73
30
  # * UncaughtThrowError
74
- #
75
31
  # * EncodingError
76
32
  # * FiberError
77
33
  # * IOError
78
34
  # * EOFError
79
- #
80
35
  # * IndexError
81
36
  # * KeyError
82
37
  # * StopIteration
83
38
  # * ClosedQueueError
84
- #
85
- #
86
39
  # * LocalJumpError
87
40
  # * NameError
88
41
  # * NoMethodError
89
- #
90
42
  # * RangeError
91
43
  # * FloatDomainError
92
- #
93
44
  # * RegexpError
94
45
  # * RuntimeError
95
46
  # * FrozenError
96
- #
97
47
  # * SystemCallError
98
- # * Errno::*
99
- #
48
+ # * Errno (and its subclasses, representing system errors)
100
49
  # * ThreadError
101
50
  # * TypeError
102
51
  # * ZeroDivisionError
103
- #
104
52
  # * SystemExit
105
53
  # * SystemStackError
106
- # * fatal
54
+ # * [fatal](https://docs.ruby-lang.org/en/master/fatal.html)
107
55
  #
108
56
  class Exception
109
57
  # <!--
110
58
  # rdoc-file=error.c
111
- # - Exception.to_tty? -> true or false
59
+ # - Exception.to_tty? -> true or false
112
60
  # -->
113
- # Returns `true` if exception messages will be sent to a tty.
61
+ # Returns `true` if exception messages will be sent to a terminal device.
114
62
  #
115
63
  def self.to_tty?: () -> bool
116
64
 
117
65
  # <!--
118
66
  # rdoc-file=error.c
119
- # - exc.exception([string]) -> an_exception or exc
67
+ # - exception(message = nil) -> self or new_exception
120
68
  # -->
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`.
69
+ # Returns an exception object of the same class as `self`; useful for creating a
70
+ # similar exception, but with a different message.
71
+ #
72
+ # With `message` `nil`, returns `self`:
73
+ #
74
+ # x0 = StandardError.new('Boom') # => #<StandardError: Boom>
75
+ # x1 = x0.exception # => #<StandardError: Boom>
76
+ # x0.__id__ == x1.__id__ # => true
77
+ #
78
+ # With [string-convertible
79
+ # object](rdoc-ref:implicit_conversion.rdoc@String-Convertible+Objects)
80
+ # `message` (even the same as the original message), returns a new exception
81
+ # object whose class is the same as `self`, and whose message is the given
82
+ # `message`:
83
+ #
84
+ # x1 = x0.exception('Boom') # => #<StandardError: Boom>
85
+ # x0..equal?(x1) # => false
124
86
  #
125
87
  def self.exception: (?string | _ToS msg) -> instance
126
88
 
127
89
  # <!--
128
90
  # rdoc-file=error.c
129
- # - exc == obj -> true or false
91
+ # - self == object -> true or false
130
92
  # -->
131
- # Equality---If *obj* is not an Exception, returns `false`. Otherwise, returns
132
- # `true` if *exc* and *obj* share same class, messages, and backtrace.
93
+ # Returns whether `object` is the same class as `self` and its #message and
94
+ # #backtrace are equal to those of `self`.
133
95
  #
134
96
  def ==: (untyped obj) -> bool
135
97
 
136
98
  # <!--
137
99
  # rdoc-file=error.c
138
- # - exception.backtrace -> array or nil
100
+ # - backtrace -> array or nil
139
101
  # -->
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.''
102
+ # Returns a backtrace value for `self`; the returned value depends on the form
103
+ # of the stored backtrace value:
143
104
  #
144
- # def a
145
- # raise "boom"
146
- # end
105
+ # * Array of Thread::Backtrace::Location objects: returns the array of strings
106
+ # given by `Exception#backtrace_locations.map {|loc| loc.to_s }`. This is
107
+ # the normal case, where the backtrace value was stored by Kernel#raise.
108
+ # * Array of strings: returns that array. This is the unusual case, where the
109
+ # backtrace value was explicitly stored as an array of strings.
110
+ # * `nil`: returns `nil`.
147
111
  #
148
- # def b
149
- # a()
150
- # end
112
+ # Example:
151
113
  #
152
114
  # begin
153
- # b()
154
- # rescue => detail
155
- # print detail.backtrace.join("\n")
115
+ # 1 / 0
116
+ # rescue => x
117
+ # x.backtrace.take(2)
156
118
  # end
119
+ # # => ["(irb):132:in `/'", "(irb):132:in `<top (required)>'"]
157
120
  #
158
- # *produces:*
159
- #
160
- # prog.rb:2:in `a'
161
- # prog.rb:6:in `b'
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
121
+ # see [Backtraces](rdoc-ref:exceptions.md@Backtraces).
169
122
  #
170
123
  def backtrace: () -> Array[String]?
171
124
 
172
125
  # <!--
173
126
  # rdoc-file=error.c
174
- # - exception.backtrace_locations -> array or nil
127
+ # - backtrace_locations -> array or nil
175
128
  # -->
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.
129
+ # Returns a backtrace value for `self`; the returned value depends on the form
130
+ # of the stored backtrace value:
131
+ #
132
+ # * Array of Thread::Backtrace::Location objects: returns that array.
133
+ # * Array of strings or `nil`: returns `nil`.
179
134
  #
180
- # This method is not affected by Exception#set_backtrace().
135
+ # Example:
136
+ #
137
+ # begin
138
+ # 1 / 0
139
+ # rescue => x
140
+ # x.backtrace_locations.take(2)
141
+ # end
142
+ # # => ["(irb):150:in `/'", "(irb):150:in `<top (required)>'"]
143
+ #
144
+ # See [Backtraces](rdoc-ref:exceptions.md@Backtraces).
181
145
  #
182
146
  def backtrace_locations: () -> Array[Thread::Backtrace::Location]?
183
147
 
184
148
  # <!--
185
149
  # rdoc-file=error.c
186
- # - exception.cause -> an_exception or nil
150
+ # - cause -> exception or nil
187
151
  # -->
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.
152
+ # Returns the previous value of global variable `$!`, which may be `nil` (see
153
+ # [Global Variables](rdoc-ref:exceptions.md@Global+Variables)):
154
+ #
155
+ # begin
156
+ # raise('Boom 0')
157
+ # rescue => x0
158
+ # puts "Exception: #{x0}; $!: #{$!}; cause: #{x0.cause.inspect}."
159
+ # begin
160
+ # raise('Boom 1')
161
+ # rescue => x1
162
+ # puts "Exception: #{x1}; $!: #{$!}; cause: #{x1.cause}."
163
+ # begin
164
+ # raise('Boom 2')
165
+ # rescue => x2
166
+ # puts "Exception: #{x2}; $!: #{$!}; cause: #{x2.cause}."
167
+ # end
168
+ # end
169
+ # end
170
+ #
171
+ # Output:
172
+ #
173
+ # Exception: Boom 0; $!: Boom 0; cause: nil.
174
+ # Exception: Boom 1; $!: Boom 1; cause: Boom 0.
175
+ # Exception: Boom 2; $!: Boom 2; cause: Boom 1.
191
176
  #
192
177
  def cause: () -> Exception?
193
178
 
194
179
  # <!--
195
180
  # rdoc-file=error.c
196
- # - exception.detailed_message(highlight: bool, **opt) -> string
181
+ # - detailed_message(highlight: false, **kwargs) -> string
197
182
  # -->
198
- # Processes a string returned by #message.
183
+ # Returns the message string with enhancements:
184
+ #
185
+ # * Includes the exception class name in the first line.
186
+ # * If the value of keyword `highlight` is `true`, includes bolding and
187
+ # underlining ANSI codes (see below) to enhance the appearance of the
188
+ # message.
199
189
  #
200
- # It may add the class name of the exception to the end of the first line. Also,
201
- # when `highlight` keyword is true, it adds ANSI escape sequences to make the
202
- # message bold.
190
+ # Examples:
203
191
  #
204
- # If you override this method, it must be tolerant for unknown keyword
205
- # arguments. All keyword arguments passed to #full_message are delegated to this
206
- # method.
192
+ # begin
193
+ # 1 / 0
194
+ # rescue => x
195
+ # p x.message
196
+ # p x.detailed_message # Class name added.
197
+ # p x.detailed_message(highlight: true) # Class name, bolding, and underlining added.
198
+ # end
207
199
  #
208
- # This method is overridden by did_you_mean and error_highlight to add their
209
- # information.
200
+ # Output:
210
201
  #
211
- # A user-defined exception class can also define their own `detailed_message`
212
- # method to add supplemental information. When `highlight` is true, it can
213
- # return a string containing escape sequences, but use widely-supported ones. It
214
- # is recommended to limit the following codes:
202
+ # "divided by 0"
203
+ # "divided by 0 (ZeroDivisionError)"
204
+ # "\e[1mdivided by 0 (\e[1;4mZeroDivisionError\e[m\e[1m)\e[m"
215
205
  #
216
- # * Reset (`\e[0m`)
217
- # * Bold (`\e[1m`)
218
- # * Underline (`\e[4m`)
219
- # * Foreground color except white and black
220
- # * Red (`\e[31m`)
221
- # * Green (`\e[32m`)
222
- # * Yellow (`\e[33m`)
223
- # * Blue (`\e[34m`)
224
- # * Magenta (`\e[35m`)
225
- # * Cyan (`\e[36m`)
206
+ # This method is overridden by some gems in the Ruby standard library to add
207
+ # information:
226
208
  #
209
+ # * DidYouMean::Correctable#detailed_message.
210
+ # * ErrorHighlight::CoreExt#detailed_message.
211
+ # * SyntaxSuggest#detailed_message.
227
212
  #
213
+ # An overriding method must be tolerant of passed keyword arguments, which may
214
+ # include (but may not be limited to):
228
215
  #
229
- # Use escape sequences carefully even if `highlight` is true. Do not use escape
230
- # sequences to express essential information; the message should be readable
231
- # even if all escape sequences are ignored.
216
+ # * `:highlight`.
217
+ # * `:did_you_mean`.
218
+ # * `:error_highlight`.
219
+ # * `:syntax_suggest`.
220
+ #
221
+ # An overriding method should also be careful with ANSI code enhancements; see
222
+ # [Messages](rdoc-ref:exceptions.md@Messages).
232
223
  #
233
224
  def detailed_message: (?highlight: bool?, **untyped ignored) -> String
234
225
 
235
226
  # <!--
236
227
  # rdoc-file=error.c
237
- # - exc.exception([string]) -> an_exception or exc
228
+ # - exception(message = nil) -> self or new_exception
238
229
  # -->
239
- # With no argument, or if the argument is the same as the receiver, return the
240
- # receiver. Otherwise, create a new exception object of the same class as the
241
- # receiver, but with a message equal to `string.to_str`.
230
+ # Returns an exception object of the same class as `self`; useful for creating a
231
+ # similar exception, but with a different message.
232
+ #
233
+ # With `message` `nil`, returns `self`:
234
+ #
235
+ # x0 = StandardError.new('Boom') # => #<StandardError: Boom>
236
+ # x1 = x0.exception # => #<StandardError: Boom>
237
+ # x0.__id__ == x1.__id__ # => true
238
+ #
239
+ # With [string-convertible
240
+ # object](rdoc-ref:implicit_conversion.rdoc@String-Convertible+Objects)
241
+ # `message` (even the same as the original message), returns a new exception
242
+ # object whose class is the same as `self`, and whose message is the given
243
+ # `message`:
244
+ #
245
+ # x1 = x0.exception('Boom') # => #<StandardError: Boom>
246
+ # x0..equal?(x1) # => false
242
247
  #
243
248
  def exception: (?self) -> self
244
249
  | (string | _ToS message) -> instance
245
250
 
246
251
  # <!--
247
252
  # rdoc-file=error.c
248
- # - Exception.new(msg = nil) -> exception
249
- # - Exception.exception(msg = nil) -> exception
253
+ # - Exception.new(message = nil) -> exception
250
254
  # -->
251
- # Construct a new Exception object, optionally passing in a message.
255
+ # Returns a new exception object.
256
+ #
257
+ # The given `message` should be a [string-convertible
258
+ # object](rdoc-ref:implicit_conversion.rdoc@String-Convertible+Objects); see
259
+ # method #message; if not given, the message is the class name of the new
260
+ # instance (which may be the name of a subclass):
261
+ #
262
+ # Examples:
263
+ #
264
+ # Exception.new # => #<Exception: Exception>
265
+ # LoadError.new # => #<LoadError: LoadError> # Subclass of Exception.
266
+ # Exception.new('Boom') # => #<Exception: Boom>
252
267
  #
253
268
  def initialize: (?string | _ToS message) -> void
254
269
 
255
270
  # <!--
256
271
  # rdoc-file=error.c
257
- # - exception.inspect -> string
272
+ # - inspect -> string
258
273
  # -->
259
- # Return this exception's class name and message.
274
+ # Returns a string representation of `self`:
275
+ #
276
+ # x = RuntimeError.new('Boom')
277
+ # x.inspect # => "#<RuntimeError: Boom>"
278
+ # x = RuntimeError.new
279
+ # x.inspect # => "#<RuntimeError: RuntimeError>"
260
280
  #
261
281
  def inspect: () -> String
262
282
 
263
283
  # <!--
264
284
  # rdoc-file=error.c
265
- # - exception.message -> string
285
+ # - message -> string
266
286
  # -->
267
- # Returns the result of invoking `exception.to_s`. Normally this returns the
268
- # exception's message or name.
287
+ # Returns #to_s.
288
+ #
289
+ # See [Messages](rdoc-ref:exceptions.md@Messages).
269
290
  #
270
291
  def message: () -> String
271
292
 
272
293
  # <!--
273
294
  # rdoc-file=error.c
274
- # - exc.set_backtrace(backtrace) -> array
295
+ # - set_backtrace(value) -> value
275
296
  # -->
276
- # Sets the backtrace information associated with `exc`. The `backtrace` must be
277
- # an array of String objects or a single String in the format described in
278
- # Exception#backtrace.
297
+ # Sets the backtrace value for `self`; returns the given +value:
298
+ #
299
+ # x = RuntimeError.new('Boom')
300
+ # x.set_backtrace(%w[foo bar baz]) # => ["foo", "bar", "baz"]
301
+ # x.backtrace # => ["foo", "bar", "baz"]
279
302
  #
280
- def set_backtrace: (String | Array[String] backtrace) -> Array[String]
303
+ # The given `value` must be an array of strings, a single string, or `nil`.
304
+ #
305
+ # Does not affect the value returned by #backtrace_locations.
306
+ #
307
+ # See [Backtraces](rdoc-ref:exceptions.md@Backtraces).
308
+ #
309
+ def set_backtrace: (String | Array[String]) -> Array[String]
310
+ | (Array[Thread::Backtrace::Location]) -> Array[Thread::Backtrace::Location]
281
311
  | (nil) -> nil
282
312
 
283
313
  # <!--
284
314
  # rdoc-file=error.c
285
- # - exception.to_s -> string
315
+ # - to_s -> string
286
316
  # -->
287
- # Returns exception's message (or the name of the exception if no message is
288
- # set).
317
+ # Returns a string representation of `self`:
318
+ #
319
+ # x = RuntimeError.new('Boom')
320
+ # x.to_s # => "Boom"
321
+ # x = RuntimeError.new
322
+ # x.to_s # => "RuntimeError"
289
323
  #
290
324
  def to_s: () -> String
291
325
 
292
326
  # <!--
293
327
  # rdoc-file=error.c
294
- # - exception.full_message(highlight: bool, order: [:top or :bottom]) -> string
328
+ # - full_message(highlight: true, order: :top) -> string
295
329
  # -->
296
- # Returns formatted string of *exception*. The returned string is formatted
297
- # using the same format that Ruby uses when printing an uncaught exceptions to
298
- # stderr.
299
- #
300
- # If *highlight* is `true` the default error handler will send the messages to a
301
- # tty.
302
- #
303
- # *order* must be either of `:top` or `:bottom`, and places the error message
304
- # and the innermost backtrace come at the top or the bottom.
305
- #
306
- # The default values of these options depend on `$stderr` and its `tty?` at the
307
- # timing of a call.
330
+ # Returns an enhanced message string:
331
+ #
332
+ # * Includes the exception class name.
333
+ # * If the value of keyword `highlight` is true (not `nil` or `false`),
334
+ # includes bolding ANSI codes (see below) to enhance the appearance of the
335
+ # message.
336
+ # * Includes the [backtrace](rdoc-ref:exceptions.md@Backtraces):
337
+ #
338
+ # * If the value of keyword `order` is `:top` (the default), lists the
339
+ # error message and the innermost backtrace entry first.
340
+ # * If the value of keyword `order` is `:bottom`, lists the error message
341
+ # the the innermost entry last.
342
+ #
343
+ # Example:
344
+ #
345
+ # def baz
346
+ # begin
347
+ # 1 / 0
348
+ # rescue => x
349
+ # pp x.message
350
+ # pp x.full_message(highlight: false).split("\n")
351
+ # pp x.full_message.split("\n")
352
+ # end
353
+ # end
354
+ # def bar; baz; end
355
+ # def foo; bar; end
356
+ # foo
357
+ #
358
+ # Output:
359
+ #
360
+ # "divided by 0"
361
+ # ["t.rb:3:in `/': divided by 0 (ZeroDivisionError)",
362
+ # "\tfrom t.rb:3:in `baz'",
363
+ # "\tfrom t.rb:10:in `bar'",
364
+ # "\tfrom t.rb:11:in `foo'",
365
+ # "\tfrom t.rb:12:in `<main>'"]
366
+ # ["t.rb:3:in `/': \e[1mdivided by 0 (\e[1;4mZeroDivisionError\e[m\e[1m)\e[m",
367
+ # "\tfrom t.rb:3:in `baz'",
368
+ # "\tfrom t.rb:10:in `bar'",
369
+ # "\tfrom t.rb:11:in `foo'",
370
+ # "\tfrom t.rb:12:in `<main>'"]
371
+ #
372
+ # An overriding method should be careful with ANSI code enhancements; see
373
+ # [Messages](rdoc-ref:exceptions.md@Messages).
308
374
  #
309
375
  def full_message: (?highlight: bool?, ?order: (:top | :bottom | string)?) -> String
310
376
  end
data/core/fiber.rbs CHANGED
@@ -412,8 +412,10 @@ class Fiber < Object
412
412
  #
413
413
  # Raises `FiberError` if called on a Fiber belonging to another `Thread`.
414
414
  #
415
+ # See Kernel#raise for more information.
416
+ #
415
417
  def raise: (?string msg) -> untyped
416
- | (_Exception, ?string msg, ?Array[string] backtrace) -> untyped
418
+ | (_Exception, ?string msg, ?Array[string] | Array[Thread::Backtrace::Location] | nil backtrace) -> untyped
417
419
 
418
420
  # <!--
419
421
  # rdoc-file=cont.c
@@ -493,7 +495,6 @@ class Fiber < Object
493
495
  # transferred back, and if it had yielded, it only can be resumed back.
494
496
  # After that, it again can transfer or yield.
495
497
  #
496
- #
497
498
  # If those rules are broken FiberError is raised.
498
499
  #
499
500
  # For an individual Fiber design, yield/resume is easier to use (the Fiber just