rbs 3.7.0 → 3.8.0.pre.1
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.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/ruby.yml +7 -7
- data/CHANGELOG.md +52 -0
- data/core/array.rbs +1743 -1580
- data/core/basic_object.rbs +38 -35
- data/core/comparable.rbs +1 -1
- data/core/complex.rbs +165 -93
- data/core/data.rbs +1 -1
- data/core/dir.rbs +1 -17
- data/core/encoding.rbs +12 -6
- data/core/enumerable.rbs +270 -266
- data/core/enumerator.rbs +0 -2
- data/core/env.rbs +1 -1
- data/core/errno.rbs +33 -16
- data/core/errors.rbs +2 -2
- data/core/exception.rbs +236 -170
- data/core/fiber.rbs +3 -2
- data/core/file.rbs +32 -74
- data/core/float.rbs +125 -72
- data/core/gc.rbs +138 -40
- data/core/hash.rbs +120 -141
- data/core/integer.rbs +79 -50
- data/core/io/buffer.rbs +49 -43
- data/core/io.rbs +97 -144
- data/core/kernel.rbs +290 -200
- data/core/match_data.rbs +76 -2
- data/core/math.rbs +0 -36
- data/core/module.rbs +28 -23
- data/core/nil_class.rbs +0 -3
- data/core/numeric.rbs +100 -103
- data/core/object.rbs +0 -4
- data/core/object_space/weak_key_map.rbs +3 -4
- data/core/object_space.rbs +3 -3
- data/core/proc.rbs +0 -2
- data/core/process.rbs +109 -57
- data/core/ractor.rbs +37 -4
- data/core/range.rbs +114 -87
- data/core/rational.rbs +0 -2
- data/core/rbs/unnamed/argf.rbs +234 -33
- data/core/rbs/unnamed/env_class.rbs +35 -53
- data/core/rbs/unnamed/random.rbs +1 -2
- data/core/regexp.rbs +4 -52
- data/core/ruby_vm.rbs +88 -9
- data/core/rubygems/config_file.rbs +3 -0
- data/core/rubygems/errors.rbs +0 -5
- data/core/rubygems/platform.rbs +0 -9
- data/core/rubygems/rubygems.rbs +0 -5
- data/core/rubygems/version.rbs +6 -6
- data/core/set.rbs +3 -15
- data/core/string.rbs +130 -136
- data/core/struct.rbs +6 -18
- data/core/symbol.rbs +14 -21
- data/core/thread.rbs +32 -35
- data/core/time.rbs +127 -50
- data/core/trace_point.rbs +16 -0
- data/core/true_class.rbs +0 -1
- data/core/warning.rbs +9 -2
- data/docs/architecture.md +1 -1
- data/docs/syntax.md +1 -1
- data/ext/rbs_extension/location.c +29 -19
- data/ext/rbs_extension/parser.c +267 -292
- data/ext/rbs_extension/parserstate.c +56 -22
- data/lib/rbs/annotate/annotations.rb +3 -3
- data/lib/rbs/annotate/rdoc_source.rb +2 -2
- data/lib/rbs/cli/diff.rb +3 -3
- data/lib/rbs/cli/validate.rb +1 -1
- data/lib/rbs/cli.rb +13 -13
- data/lib/rbs/collection/config.rb +3 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +3 -3
- data/lib/rbs/environment_loader.rb +1 -1
- data/lib/rbs/namespace.rb +1 -0
- data/lib/rbs/parser_aux.rb +2 -2
- data/lib/rbs/prototype/rb.rb +11 -8
- data/lib/rbs/prototype/rbi.rb +9 -5
- data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
- data/lib/rbs/prototype/runtime.rb +4 -5
- data/lib/rbs/type_name.rb +14 -9
- data/lib/rbs/unit_test/type_assertions.rb +2 -2
- data/lib/rbs/validator.rb +3 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +2 -2
- data/rbs.gemspec +4 -0
- data/sig/ancestor_graph.rbs +4 -4
- data/sig/namespace.rbs +2 -3
- data/sig/resolver/constant_resolver.rbs +2 -2
- data/sig/resolver/context.rbs +1 -1
- data/sig/type_alias_regularity.rbs +5 -5
- data/sig/typename.rbs +8 -5
- data/sig/use_map.rbs +1 -1
- data/sig/validator.rbs +2 -2
- data/stdlib/base64/0/base64.rbs +0 -9
- data/stdlib/benchmark/0/benchmark.rbs +11 -2
- data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
- data/stdlib/cgi/0/core.rbs +47 -0
- data/stdlib/coverage/0/coverage.rbs +0 -3
- data/stdlib/csv/0/csv.rbs +18 -58
- data/stdlib/date/0/date.rbs +4 -19
- data/stdlib/did_you_mean/0/did_you_mean.rbs +0 -5
- data/stdlib/digest/0/digest.rbs +25 -2
- data/stdlib/erb/0/erb.rbs +0 -1
- data/stdlib/etc/0/etc.rbs +51 -34
- data/stdlib/fileutils/0/fileutils.rbs +3 -44
- data/stdlib/io-console/0/io-console.rbs +69 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +8 -4
- data/stdlib/json/0/json.rbs +56 -71
- data/stdlib/logger/0/log_device.rbs +1 -1
- data/stdlib/logger/0/logger.rbs +3 -18
- data/stdlib/net-http/0/net-http.rbs +19 -77
- data/stdlib/nkf/0/nkf.rbs +30 -0
- data/stdlib/objspace/0/objspace.rbs +1 -2
- data/stdlib/observable/0/observable.rbs +1 -1
- data/stdlib/open-uri/0/open-uri.rbs +52 -0
- data/stdlib/open3/0/open3.rbs +0 -8
- data/stdlib/openssl/0/openssl.rbs +136 -69
- data/stdlib/optparse/0/optparse.rbs +58 -18
- data/stdlib/pathname/0/pathname.rbs +2 -8
- data/stdlib/pp/0/pp.rbs +3 -1
- data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
- data/stdlib/pstore/0/pstore.rbs +0 -6
- data/stdlib/psych/0/psych.rbs +15 -4
- data/stdlib/pty/0/pty.rbs +46 -4
- data/stdlib/rdoc/0/code_object.rbs +0 -4
- data/stdlib/rdoc/0/markup.rbs +10 -12
- data/stdlib/rdoc/0/rdoc.rbs +1 -2
- data/stdlib/resolv/0/resolv.rbs +8 -3
- data/stdlib/ripper/0/ripper.rbs +0 -2
- data/stdlib/securerandom/0/securerandom.rbs +0 -2
- data/stdlib/shellwords/0/shellwords.rbs +11 -12
- data/stdlib/singleton/0/singleton.rbs +0 -1
- data/stdlib/socket/0/addrinfo.rbs +0 -1
- data/stdlib/socket/0/basic_socket.rbs +0 -5
- data/stdlib/socket/0/socket.rbs +49 -25
- data/stdlib/socket/0/tcp_server.rbs +0 -3
- data/stdlib/socket/0/tcp_socket.rbs +58 -3
- data/stdlib/socket/0/udp_socket.rbs +0 -1
- data/stdlib/socket/0/unix_server.rbs +0 -3
- data/stdlib/strscan/0/string_scanner.rbs +1265 -422
- data/stdlib/tempfile/0/tempfile.rbs +135 -28
- data/stdlib/time/0/time.rbs +48 -35
- data/stdlib/timeout/0/timeout.rbs +11 -8
- data/stdlib/tmpdir/0/tmpdir.rbs +8 -1
- data/stdlib/tsort/0/tsort.rbs +0 -4
- data/stdlib/uri/0/common.rbs +11 -30
- data/stdlib/uri/0/ftp.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +22 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
- data/stdlib/zlib/0/buf_error.rbs +1 -70
- data/stdlib/zlib/0/data_error.rbs +1 -70
- data/stdlib/zlib/0/deflate.rbs +8 -72
- data/stdlib/zlib/0/error.rbs +1 -70
- data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
- data/stdlib/zlib/0/gzip_file.rbs +1 -71
- data/stdlib/zlib/0/gzip_reader.rbs +3 -74
- data/stdlib/zlib/0/gzip_writer.rbs +1 -70
- data/stdlib/zlib/0/inflate.rbs +4 -71
- data/stdlib/zlib/0/mem_error.rbs +1 -70
- data/stdlib/zlib/0/need_dict.rbs +1 -70
- data/stdlib/zlib/0/stream_end.rbs +1 -70
- data/stdlib/zlib/0/stream_error.rbs +1 -70
- data/stdlib/zlib/0/version_error.rbs +1 -70
- data/stdlib/zlib/0/zlib.rbs +0 -2
- data/stdlib/zlib/0/zstream.rbs +4 -72
- 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
data/core/errno.rbs
CHANGED
|
@@ -1,25 +1,42 @@
|
|
|
1
1
|
# <!-- rdoc-file=error.c -->
|
|
2
|
-
#
|
|
3
|
-
#
|
|
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
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
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
|
-
#
|
|
13
|
-
#
|
|
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
|
-
#
|
|
16
|
-
# Errno::
|
|
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
|
-
#
|
|
20
|
-
# available as the constants of Errno.
|
|
17
|
+
# Each such class is:
|
|
21
18
|
#
|
|
22
|
-
#
|
|
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
|
|
3
|
-
#
|
|
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
|
|
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
|
-
#
|
|
12
|
-
# NameError#name.
|
|
16
|
+
# ## Built-In Exception Class Hierarchy
|
|
13
17
|
#
|
|
14
|
-
#
|
|
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?
|
|
59
|
+
# - Exception.to_tty? -> true or false
|
|
112
60
|
# -->
|
|
113
|
-
# Returns `true` if exception messages will be sent to a
|
|
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
|
-
# -
|
|
67
|
+
# - exception(message = nil) -> self or new_exception
|
|
120
68
|
# -->
|
|
121
|
-
#
|
|
122
|
-
#
|
|
123
|
-
#
|
|
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
|
-
# -
|
|
91
|
+
# - self == object -> true or false
|
|
130
92
|
# -->
|
|
131
|
-
#
|
|
132
|
-
#
|
|
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
|
-
# -
|
|
100
|
+
# - backtrace -> array or nil
|
|
139
101
|
# -->
|
|
140
|
-
# Returns
|
|
141
|
-
# of
|
|
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
|
-
#
|
|
145
|
-
#
|
|
146
|
-
#
|
|
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
|
-
#
|
|
149
|
-
# a()
|
|
150
|
-
# end
|
|
112
|
+
# Example:
|
|
151
113
|
#
|
|
152
114
|
# begin
|
|
153
|
-
#
|
|
154
|
-
# rescue =>
|
|
155
|
-
#
|
|
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
|
-
#
|
|
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
|
-
# -
|
|
127
|
+
# - backtrace_locations -> array or nil
|
|
175
128
|
# -->
|
|
176
|
-
# Returns
|
|
177
|
-
#
|
|
178
|
-
#
|
|
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
|
-
#
|
|
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
|
-
# -
|
|
150
|
+
# - cause -> exception or nil
|
|
187
151
|
# -->
|
|
188
|
-
# Returns the previous
|
|
189
|
-
#
|
|
190
|
-
#
|
|
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
|
-
# -
|
|
181
|
+
# - detailed_message(highlight: false, **kwargs) -> string
|
|
197
182
|
# -->
|
|
198
|
-
#
|
|
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
|
-
#
|
|
201
|
-
# when `highlight` keyword is true, it adds ANSI escape sequences to make the
|
|
202
|
-
# message bold.
|
|
190
|
+
# Examples:
|
|
203
191
|
#
|
|
204
|
-
#
|
|
205
|
-
#
|
|
206
|
-
#
|
|
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
|
-
#
|
|
209
|
-
# information.
|
|
200
|
+
# Output:
|
|
210
201
|
#
|
|
211
|
-
#
|
|
212
|
-
#
|
|
213
|
-
#
|
|
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
|
-
#
|
|
217
|
-
#
|
|
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
|
-
#
|
|
230
|
-
#
|
|
231
|
-
#
|
|
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
|
-
# -
|
|
228
|
+
# - exception(message = nil) -> self or new_exception
|
|
238
229
|
# -->
|
|
239
|
-
#
|
|
240
|
-
#
|
|
241
|
-
#
|
|
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(
|
|
249
|
-
# - Exception.exception(msg = nil) -> exception
|
|
253
|
+
# - Exception.new(message = nil) -> exception
|
|
250
254
|
# -->
|
|
251
|
-
#
|
|
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
|
-
# -
|
|
272
|
+
# - inspect -> string
|
|
258
273
|
# -->
|
|
259
|
-
#
|
|
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
|
-
# -
|
|
285
|
+
# - message -> string
|
|
266
286
|
# -->
|
|
267
|
-
# Returns
|
|
268
|
-
#
|
|
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
|
-
# -
|
|
295
|
+
# - set_backtrace(value) -> value
|
|
275
296
|
# -->
|
|
276
|
-
# Sets the backtrace
|
|
277
|
-
#
|
|
278
|
-
#
|
|
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
|
-
|
|
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
|
-
# -
|
|
315
|
+
# - to_s -> string
|
|
286
316
|
# -->
|
|
287
|
-
# Returns
|
|
288
|
-
#
|
|
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
|
-
# -
|
|
328
|
+
# - full_message(highlight: true, order: :top) -> string
|
|
295
329
|
# -->
|
|
296
|
-
# Returns
|
|
297
|
-
#
|
|
298
|
-
#
|
|
299
|
-
#
|
|
300
|
-
#
|
|
301
|
-
#
|
|
302
|
-
#
|
|
303
|
-
#
|
|
304
|
-
#
|
|
305
|
-
#
|
|
306
|
-
#
|
|
307
|
-
#
|
|
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
|