rbs 2.0.0 → 2.2.2
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 +34 -0
- data/.github/workflows/ruby.yml +5 -0
- data/CHANGELOG.md +82 -0
- data/README.md +6 -1
- data/Rakefile +56 -21
- data/core/array.rbs +2866 -1086
- data/core/basic_object.rbs +150 -30
- data/core/binding.rbs +33 -0
- data/core/builtin.rbs +4 -4
- data/core/class.rbs +43 -5
- data/core/comparable.rbs +57 -0
- data/core/complex.rbs +170 -4
- data/core/constants.rbs +51 -0
- data/core/deprecated.rbs +7 -0
- data/core/dir.rbs +305 -20
- data/core/encoding.rbs +1214 -77
- data/core/enumerable.rbs +2173 -234
- data/core/enumerator.rbs +448 -182
- data/core/env.rbs +448 -1
- data/core/errno.rbs +1 -10
- data/core/errors.rbs +152 -2
- data/core/exception.rbs +201 -127
- data/core/false_class.rbs +27 -0
- data/core/fiber.rbs +118 -37
- data/core/fiber_error.rbs +8 -9
- data/core/file.rbs +1060 -142
- data/core/file_test.rbs +287 -32
- data/core/float.rbs +776 -300
- data/core/gc.rbs +185 -34
- data/core/global_variables.rbs +5 -1
- data/core/hash.rbs +1582 -649
- data/core/integer.rbs +974 -204
- data/core/io/buffer.rbs +710 -0
- data/core/io/wait.rbs +29 -8
- data/core/io.rbs +2438 -417
- data/core/kernel.rbs +2319 -318
- data/core/marshal.rbs +37 -2
- data/core/match_data.rbs +123 -6
- data/core/math.rbs +126 -6
- data/core/method.rbs +226 -102
- data/core/module.rbs +421 -45
- data/core/nil_class.rbs +64 -0
- data/core/numeric.rbs +620 -142
- data/core/object.rbs +453 -81
- data/core/object_space.rbs +92 -2
- data/core/proc.rbs +482 -285
- data/core/process.rbs +443 -34
- data/core/ractor.rbs +232 -9
- data/core/random.rbs +151 -52
- data/core/range.rbs +885 -160
- data/core/rational.rbs +122 -6
- data/core/rb_config.rbs +14 -4
- data/core/refinement.rbs +44 -0
- data/core/regexp.rbs +156 -14
- data/core/ruby_vm.rbs +42 -3
- data/core/signal.rbs +78 -39
- data/core/string.rbs +2123 -567
- data/core/string_io.rbs +204 -0
- data/core/struct.rbs +283 -28
- data/core/symbol.rbs +304 -30
- data/core/thread.rbs +1288 -688
- data/core/thread_group.rbs +66 -10
- data/core/time.rbs +643 -217
- data/core/trace_point.rbs +100 -12
- data/core/true_class.rbs +24 -0
- data/core/unbound_method.rbs +73 -7
- data/core/warning.rbs +37 -12
- data/docs/CONTRIBUTING.md +40 -34
- data/docs/stdlib.md +3 -102
- data/docs/syntax.md +54 -11
- data/ext/rbs_extension/extconf.rb +1 -0
- data/ext/rbs_extension/lexer.h +5 -0
- data/ext/rbs_extension/lexstate.c +6 -0
- data/ext/rbs_extension/parser.c +85 -10
- data/ext/rbs_extension/ruby_objs.c +4 -2
- data/ext/rbs_extension/ruby_objs.h +2 -2
- data/goodcheck.yml +0 -11
- data/lib/rbs/annotate/annotations.rb +197 -0
- data/lib/rbs/annotate/formatter.rb +80 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
- data/lib/rbs/annotate/rdoc_source.rb +120 -0
- data/lib/rbs/annotate.rb +6 -0
- data/lib/rbs/ast/members.rb +21 -13
- data/lib/rbs/buffer.rb +17 -11
- data/lib/rbs/cli.rb +48 -1
- data/lib/rbs/definition_builder/method_builder.rb +28 -16
- data/lib/rbs/definition_builder.rb +6 -2
- data/lib/rbs/environment.rb +8 -4
- data/lib/rbs/location_aux.rb +12 -0
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/prototype/rb.rb +12 -0
- data/lib/rbs/type_alias_regularity.rb +6 -4
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +1 -1
- data/lib/rbs/validator.rb +6 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +54 -4
- data/lib/rbs.rb +0 -2
- data/schema/typeParam.json +3 -3
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +82 -0
- data/sig/annotate/rdoc_source.rbs +30 -0
- data/sig/buffer.rbs +6 -2
- data/sig/cli.rbs +2 -0
- data/sig/collection/{collections.rbs → sources.rbs} +0 -0
- data/sig/location.rbs +6 -0
- data/sig/members.rbs +24 -18
- data/sig/method_builder.rbs +5 -4
- data/sig/method_types.rbs +5 -1
- data/sig/polyfill.rbs +78 -0
- data/sig/validator.rbs +3 -1
- data/sig/writer.rbs +79 -2
- data/stdlib/abbrev/0/abbrev.rbs +6 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +31 -0
- data/stdlib/benchmark/0/benchmark.rbs +74 -3
- data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
- data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
- data/stdlib/cgi/0/core.rbs +649 -21
- data/stdlib/coverage/0/coverage.rbs +164 -2
- data/stdlib/csv/0/csv.rbs +2862 -398
- data/stdlib/date/0/date.rbs +483 -25
- data/stdlib/date/0/date_time.rbs +187 -12
- data/stdlib/dbm/0/dbm.rbs +152 -17
- data/stdlib/digest/0/digest.rbs +146 -0
- data/stdlib/erb/0/erb.rbs +65 -245
- data/stdlib/fiber/0/fiber.rbs +73 -91
- data/stdlib/fileutils/0/fileutils.rbs +301 -1
- data/stdlib/find/0/find.rbs +9 -0
- data/stdlib/forwardable/0/forwardable.rbs +65 -1
- data/stdlib/io-console/0/io-console.rbs +227 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
- data/stdlib/json/0/json.rbs +1147 -145
- data/stdlib/logger/0/formatter.rbs +24 -0
- data/stdlib/logger/0/log_device.rbs +64 -0
- data/stdlib/logger/0/logger.rbs +165 -13
- data/stdlib/logger/0/period.rbs +10 -0
- data/stdlib/logger/0/severity.rbs +26 -0
- data/stdlib/monitor/0/monitor.rbs +163 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
- data/stdlib/net-http/0/manifest.yaml +1 -0
- data/stdlib/net-http/0/net-http.rbs +1513 -683
- data/stdlib/nkf/0/nkf.rbs +372 -0
- data/stdlib/objspace/0/objspace.rbs +149 -90
- data/stdlib/openssl/0/openssl.rbs +8108 -71
- data/stdlib/optparse/0/optparse.rbs +487 -19
- data/stdlib/pathname/0/pathname.rbs +425 -124
- data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
- data/stdlib/prime/0/integer-extension.rbs +20 -2
- data/stdlib/prime/0/prime.rbs +88 -21
- data/stdlib/pstore/0/pstore.rbs +102 -0
- data/stdlib/pty/0/pty.rbs +64 -14
- data/stdlib/resolv/0/resolv.rbs +420 -31
- data/stdlib/rubygems/0/basic_specification.rbs +4 -1
- data/stdlib/rubygems/0/config_file.rbs +33 -1
- data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
- data/stdlib/rubygems/0/installer.rbs +13 -1
- data/stdlib/rubygems/0/path_support.rbs +4 -1
- data/stdlib/rubygems/0/platform.rbs +5 -1
- data/stdlib/rubygems/0/request_set.rbs +44 -2
- data/stdlib/rubygems/0/requirement.rbs +65 -2
- data/stdlib/rubygems/0/rubygems.rbs +407 -0
- data/stdlib/rubygems/0/source_list.rbs +13 -0
- data/stdlib/rubygems/0/specification.rbs +21 -1
- data/stdlib/rubygems/0/stream_ui.rbs +3 -1
- data/stdlib/rubygems/0/uninstaller.rbs +8 -1
- data/stdlib/rubygems/0/version.rbs +60 -157
- data/stdlib/securerandom/0/securerandom.rbs +44 -0
- data/stdlib/set/0/set.rbs +423 -109
- data/stdlib/shellwords/0/shellwords.rbs +55 -77
- data/stdlib/singleton/0/singleton.rbs +20 -0
- data/stdlib/socket/0/addrinfo.rbs +210 -9
- data/stdlib/socket/0/basic_socket.rbs +103 -11
- data/stdlib/socket/0/ip_socket.rbs +31 -9
- data/stdlib/socket/0/socket.rbs +586 -38
- data/stdlib/socket/0/tcp_server.rbs +22 -2
- data/stdlib/socket/0/tcp_socket.rbs +12 -1
- data/stdlib/socket/0/udp_socket.rbs +25 -2
- data/stdlib/socket/0/unix_server.rbs +22 -2
- data/stdlib/socket/0/unix_socket.rbs +45 -5
- data/stdlib/strscan/0/string_scanner.rbs +210 -9
- data/stdlib/tempfile/0/tempfile.rbs +58 -10
- data/stdlib/time/0/time.rbs +208 -116
- data/stdlib/timeout/0/timeout.rbs +10 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
- data/stdlib/tsort/0/cyclic.rbs +1 -0
- data/stdlib/tsort/0/interfaces.rbs +1 -0
- data/stdlib/tsort/0/tsort.rbs +42 -0
- data/stdlib/uri/0/common.rbs +57 -8
- data/stdlib/uri/0/file.rbs +55 -109
- data/stdlib/uri/0/ftp.rbs +6 -3
- data/stdlib/uri/0/generic.rbs +558 -329
- data/stdlib/uri/0/http.rbs +60 -114
- data/stdlib/uri/0/https.rbs +8 -102
- data/stdlib/uri/0/ldap.rbs +143 -137
- data/stdlib/uri/0/ldaps.rbs +8 -102
- data/stdlib/uri/0/mailto.rbs +3 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
- data/stdlib/uri/0/ws.rbs +6 -3
- data/stdlib/uri/0/wss.rbs +5 -3
- data/stdlib/yaml/0/dbm.rbs +151 -87
- data/stdlib/yaml/0/store.rbs +6 -0
- data/stdlib/zlib/0/zlib.rbs +90 -31
- metadata +18 -6
- data/lib/rbs/location.rb +0 -221
- data/sig/char_scanner.rbs +0 -9
data/core/exception.rbs
CHANGED
|
@@ -1,195 +1,269 @@
|
|
|
1
|
-
#
|
|
2
|
-
# to communicate between
|
|
3
|
-
#
|
|
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
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
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
|
-
#
|
|
11
|
+
# Some built-in subclasses of Exception have additional methods: e.g.,
|
|
12
|
+
# NameError#name.
|
|
60
13
|
#
|
|
61
|
-
#
|
|
14
|
+
# ## Defaults
|
|
62
15
|
#
|
|
63
|
-
#
|
|
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
|
-
#
|
|
21
|
+
# ## Global Variables
|
|
68
22
|
#
|
|
69
|
-
#
|
|
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
|
-
#
|
|
29
|
+
# ## Custom Exceptions
|
|
75
30
|
#
|
|
76
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
81
|
-
#
|
|
82
|
-
# - [IOError](https://ruby-doc.org/core-2.6.3/IOError.html)
|
|
40
|
+
# For example:
|
|
83
41
|
#
|
|
84
|
-
#
|
|
42
|
+
# class MyLibrary
|
|
43
|
+
# class Error < ::StandardError
|
|
44
|
+
# end
|
|
85
45
|
#
|
|
86
|
-
#
|
|
46
|
+
# class WidgetError < Error
|
|
47
|
+
# end
|
|
87
48
|
#
|
|
88
|
-
#
|
|
49
|
+
# class FrobError < Error
|
|
50
|
+
# end
|
|
89
51
|
#
|
|
90
|
-
#
|
|
52
|
+
# end
|
|
91
53
|
#
|
|
92
|
-
#
|
|
54
|
+
# To handle both MyLibrary::WidgetError and MyLibrary::FrobError the library
|
|
55
|
+
# user can rescue MyLibrary::Error.
|
|
93
56
|
#
|
|
94
|
-
#
|
|
57
|
+
# ## Built-In Exception Classes
|
|
95
58
|
#
|
|
96
|
-
#
|
|
59
|
+
# The built-in subclasses of Exception are:
|
|
97
60
|
#
|
|
98
|
-
#
|
|
61
|
+
# * NoMemoryError
|
|
62
|
+
# * ScriptError
|
|
63
|
+
# * LoadError
|
|
64
|
+
# * NotImplementedError
|
|
65
|
+
# * SyntaxError
|
|
99
66
|
#
|
|
100
|
-
#
|
|
67
|
+
# * SecurityError
|
|
68
|
+
# * SignalException
|
|
69
|
+
# * Interrupt
|
|
101
70
|
#
|
|
102
|
-
#
|
|
71
|
+
# * StandardError
|
|
72
|
+
# * ArgumentError
|
|
73
|
+
# * UncaughtThrowError
|
|
103
74
|
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
75
|
+
# * EncodingError
|
|
76
|
+
# * FiberError
|
|
77
|
+
# * IOError
|
|
78
|
+
# * EOFError
|
|
106
79
|
#
|
|
107
|
-
#
|
|
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
|
-
#
|
|
86
|
+
# * LocalJumpError
|
|
87
|
+
# * NameError
|
|
88
|
+
# * NoMethodError
|
|
112
89
|
#
|
|
113
|
-
#
|
|
90
|
+
# * RangeError
|
|
91
|
+
# * FloatDomainError
|
|
114
92
|
#
|
|
115
|
-
#
|
|
93
|
+
# * RegexpError
|
|
94
|
+
# * RuntimeError
|
|
95
|
+
# * FrozenError
|
|
116
96
|
#
|
|
117
|
-
#
|
|
97
|
+
# * SystemCallError
|
|
98
|
+
# * Errno::*
|
|
118
99
|
#
|
|
119
|
-
#
|
|
100
|
+
# * ThreadError
|
|
101
|
+
# * TypeError
|
|
102
|
+
# * ZeroDivisionError
|
|
120
103
|
#
|
|
121
|
-
#
|
|
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
|
-
#
|
|
132
|
-
#
|
|
133
|
-
# or
|
|
134
|
-
#
|
|
135
|
-
#
|
|
136
|
-
#
|
|
137
|
-
#
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
#
|
|
141
|
-
#
|
|
142
|
-
#
|
|
143
|
-
#
|
|
144
|
-
#
|
|
145
|
-
#
|
|
146
|
-
#
|
|
147
|
-
#
|
|
148
|
-
#
|
|
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
|
-
#
|
|
159
|
-
#
|
|
160
|
-
#
|
|
161
|
-
#
|
|
162
|
-
#
|
|
163
|
-
#
|
|
164
|
-
#
|
|
165
|
-
#
|
|
166
|
-
#
|
|
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
|
-
#
|
|
171
|
-
#
|
|
172
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
184
|
-
#
|
|
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
|
-
#
|
|
191
|
-
#
|
|
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
|
-
#
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# the programmer and not the
|
|
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
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
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
|
|
14
|
-
#
|
|
15
|
-
#
|
|
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
|
|
19
|
-
#
|
|
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
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
# end
|
|
23
|
+
# fiber = Fiber.new do
|
|
24
|
+
# Fiber.yield 1
|
|
25
|
+
# 2
|
|
26
|
+
# end
|
|
28
27
|
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
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
|
|
41
|
-
#
|
|
42
|
-
#
|
|
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
|
-
#
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
# end
|
|
44
|
+
# fiber = Fiber.new do |first|
|
|
45
|
+
# second = Fiber.yield first + 2
|
|
46
|
+
# end
|
|
51
47
|
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
2
|
-
#
|
|
3
|
-
# attempting to call/resume a dead fiber, attempting to yield from the
|
|
4
|
-
#
|
|
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
|