rbs 4.0.0.dev.4 → 4.0.0.dev.5
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/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +11 -8
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +17 -34
- data/.github/workflows/typecheck.yml +2 -2
- data/.github/workflows/valgrind.yml +42 -0
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +1 -1
- data/README.md +1 -1
- data/Rakefile +32 -5
- data/config.yml +46 -0
- data/core/array.rbs +96 -46
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/comparable.rbs +13 -6
- data/core/complex.rbs +55 -41
- data/core/dir.rbs +4 -4
- data/core/encoding.rbs +7 -10
- data/core/enumerable.rbs +90 -3
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +63 -1
- data/core/errno.rbs +8 -0
- data/core/errors.rbs +28 -1
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +40 -20
- data/core/file.rbs +108 -78
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +225 -69
- data/core/gc.rbs +417 -281
- data/core/hash.rbs +1023 -727
- data/core/integer.rbs +104 -110
- data/core/io/buffer.rbs +21 -10
- data/core/io/wait.rbs +11 -33
- data/core/io.rbs +82 -19
- data/core/kernel.rbs +70 -59
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +42 -3
- data/core/method.rbs +63 -27
- data/core/module.rbs +103 -26
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +43 -35
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +21 -15
- data/core/pathname.rbs +1272 -0
- data/core/proc.rbs +30 -25
- data/core/process.rbs +4 -2
- data/core/ractor.rbs +361 -509
- data/core/random.rbs +17 -0
- data/core/range.rbs +113 -16
- data/core/rational.rbs +56 -85
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +4 -113
- data/core/regexp.rbs +25 -20
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +6 -4
- data/core/rubygems/errors.rbs +3 -70
- data/core/rubygems/rubygems.rbs +11 -79
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +488 -359
- data/core/signal.rbs +24 -14
- data/core/string.rbs +3171 -1241
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +17 -11
- data/core/thread.rbs +95 -33
- data/core/time.rbs +35 -9
- data/core/trace_point.rbs +7 -4
- data/core/unbound_method.rbs +14 -6
- data/docs/aliases.md +79 -0
- data/docs/collection.md +2 -2
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +470 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +33 -4
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +77 -3
- data/ext/rbs_extension/ast_translation.h +3 -0
- data/ext/rbs_extension/class_constants.c +8 -2
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/extconf.rb +5 -1
- data/ext/rbs_extension/legacy_location.c +5 -5
- data/ext/rbs_extension/main.c +37 -20
- data/include/rbs/ast.h +85 -38
- data/include/rbs/defines.h +27 -0
- data/include/rbs/lexer.h +30 -11
- data/include/rbs/parser.h +6 -6
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -1
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +137 -0
- data/lib/rbs/ast/ruby/comment_block.rb +24 -0
- data/lib/rbs/ast/ruby/declarations.rb +198 -3
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/members.rb +159 -1
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +20 -15
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -51
- data/lib/rbs/cli.rb +52 -19
- data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +20 -0
- data/lib/rbs/definition_builder.rb +91 -2
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +227 -74
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -7
- data/lib/rbs/inline_parser.rb +341 -5
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/parser_aux.rb +2 -2
- data/lib/rbs/prototype/rb.rb +2 -2
- data/lib/rbs/prototype/rbi.rb +2 -0
- data/lib/rbs/prototype/runtime.rb +8 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +116 -38
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +16 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +27 -27
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +3 -2
- data/schema/typeParam.json +17 -1
- data/sig/ast/ruby/annotations.rbs +124 -0
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +87 -1
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +13 -4
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -1
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser.rbs +39 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -1
- data/sig/method_builder.rbs +3 -1
- data/sig/method_types.rbs +1 -1
- data/sig/parser.rbs +16 -2
- data/sig/resolver/type_name_resolver.rbs +35 -7
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- data/sig/types.rbs +4 -4
- data/src/ast.c +80 -1
- data/src/lexer.c +1392 -1313
- data/src/lexer.re +3 -0
- data/src/lexstate.c +58 -37
- data/src/location.c +4 -4
- data/src/parser.c +412 -145
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -71
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -10
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +3 -1
- data/stdlib/date/0/date.rbs +67 -59
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +737 -347
- data/stdlib/fileutils/0/fileutils.rbs +20 -14
- data/stdlib/forwardable/0/forwardable.rbs +3 -0
- data/stdlib/json/0/json.rbs +82 -28
- data/stdlib/net-http/0/net-http.rbs +3 -0
- data/stdlib/objspace/0/objspace.rbs +9 -27
- data/stdlib/open-uri/0/open-uri.rbs +40 -0
- data/stdlib/open3/0/open3.rbs +459 -1
- data/stdlib/openssl/0/openssl.rbs +331 -228
- data/stdlib/optparse/0/optparse.rbs +8 -3
- data/stdlib/pathname/0/pathname.rbs +9 -1379
- data/stdlib/psych/0/psych.rbs +4 -4
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +2 -2
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +6 -19
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/socket.rbs +13 -1
- data/stdlib/socket/0/tcp_socket.rbs +10 -2
- data/stdlib/stringio/0/stringio.rbs +1176 -85
- data/stdlib/strscan/0/string_scanner.rbs +31 -31
- data/stdlib/tempfile/0/tempfile.rbs +3 -3
- data/stdlib/time/0/time.rbs +1 -1
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/uri/0/common.rbs +16 -2
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +24 -16
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
- data/stdlib/zlib/0/gzip_reader.rbs +2 -2
- data/stdlib/zlib/0/gzip_writer.rbs +1 -1
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +30 -4
data/core/method.rbs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# <!-- rdoc-file=proc.c -->
|
|
2
|
-
# Method objects are created by Object#method, and are associated with a
|
|
2
|
+
# `Method` objects are created by Object#method, and are associated with a
|
|
3
3
|
# particular object (not just with a class). They may be used to invoke the
|
|
4
4
|
# method within the object, and as a block associated with an iterator. They
|
|
5
5
|
# may also be unbound from one object (creating an UnboundMethod) and bound to
|
|
@@ -54,8 +54,6 @@ class Method
|
|
|
54
54
|
#
|
|
55
55
|
def hash: () -> Integer
|
|
56
56
|
|
|
57
|
-
def dup: () -> self
|
|
58
|
-
|
|
59
57
|
# <!--
|
|
60
58
|
# rdoc-file=proc.c
|
|
61
59
|
# - meth.to_s -> string
|
|
@@ -126,7 +124,9 @@ class Method
|
|
|
126
124
|
|
|
127
125
|
# <!--
|
|
128
126
|
# rdoc-file=proc.c
|
|
129
|
-
# - meth.call(args, ...)
|
|
127
|
+
# - meth.call(args, ...) -> obj
|
|
128
|
+
# - meth[args, ...] -> obj
|
|
129
|
+
# - method === obj -> result_of_method
|
|
130
130
|
# -->
|
|
131
131
|
# Invokes the *meth* with the specified arguments, returning the method's return
|
|
132
132
|
# value.
|
|
@@ -135,23 +135,32 @@ class Method
|
|
|
135
135
|
# m.call(3) #=> 15
|
|
136
136
|
# m.call(20) #=> 32
|
|
137
137
|
#
|
|
138
|
+
# Using Method#=== allows a method object to be the target of a `when` clause in
|
|
139
|
+
# a case statement.
|
|
140
|
+
#
|
|
141
|
+
# require 'prime'
|
|
142
|
+
#
|
|
143
|
+
# case 1373
|
|
144
|
+
# when Prime.method(:prime?)
|
|
145
|
+
# # ...
|
|
146
|
+
# end
|
|
147
|
+
#
|
|
138
148
|
def call: (?) -> untyped
|
|
139
149
|
|
|
140
150
|
# <!--
|
|
141
151
|
# rdoc-file=proc.c
|
|
142
|
-
# -
|
|
152
|
+
# - self << g -> a_proc
|
|
143
153
|
# -->
|
|
144
|
-
# Returns a proc that is the composition of
|
|
145
|
-
# returned proc takes a variable number of arguments, calls *g* with them then
|
|
146
|
-
# calls this method with the result.
|
|
154
|
+
# Returns a proc that is the composition of the given `g` and this method.
|
|
147
155
|
#
|
|
148
|
-
#
|
|
149
|
-
#
|
|
150
|
-
#
|
|
156
|
+
# The returned proc takes a variable number of arguments. It first calls `g`
|
|
157
|
+
# with the arguments, then calls `self` with the return value of `g`.
|
|
158
|
+
#
|
|
159
|
+
# def f(ary) = ary << 'in f'
|
|
151
160
|
#
|
|
152
161
|
# f = self.method(:f)
|
|
153
|
-
# g = proc {|
|
|
154
|
-
#
|
|
162
|
+
# g = proc { |ary| ary << 'in proc' }
|
|
163
|
+
# (f << g).call([]) # => ["in proc", "in f"]
|
|
155
164
|
#
|
|
156
165
|
def <<: (Proc::_Callable g) -> Proc
|
|
157
166
|
|
|
@@ -163,23 +172,32 @@ class Method
|
|
|
163
172
|
# m.call(3) #=> 15
|
|
164
173
|
# m.call(20) #=> 32
|
|
165
174
|
#
|
|
175
|
+
# Using Method#=== allows a method object to be the target of a `when` clause in
|
|
176
|
+
# a case statement.
|
|
177
|
+
#
|
|
178
|
+
# require 'prime'
|
|
179
|
+
#
|
|
180
|
+
# case 1373
|
|
181
|
+
# when Prime.method(:prime?)
|
|
182
|
+
# # ...
|
|
183
|
+
# end
|
|
184
|
+
#
|
|
166
185
|
alias === call
|
|
167
186
|
|
|
168
187
|
# <!--
|
|
169
188
|
# rdoc-file=proc.c
|
|
170
|
-
# -
|
|
189
|
+
# - self >> g -> a_proc
|
|
171
190
|
# -->
|
|
172
|
-
# Returns a proc that is the composition of this method and the given
|
|
173
|
-
# returned proc takes a variable number of arguments, calls this method with
|
|
174
|
-
# them then calls *g* with the result.
|
|
191
|
+
# Returns a proc that is the composition of this method and the given `g`.
|
|
175
192
|
#
|
|
176
|
-
#
|
|
177
|
-
#
|
|
178
|
-
#
|
|
193
|
+
# The returned proc takes a variable number of arguments. It first calls `self`
|
|
194
|
+
# with the arguments, then calls `g` with the return value of `self`.
|
|
195
|
+
#
|
|
196
|
+
# def f(ary) = ary << 'in f'
|
|
179
197
|
#
|
|
180
198
|
# f = self.method(:f)
|
|
181
|
-
# g = proc {|
|
|
182
|
-
#
|
|
199
|
+
# g = proc { |ary| ary << 'in proc' }
|
|
200
|
+
# (f >> g).call([]) # => ["in f", "in proc"]
|
|
183
201
|
#
|
|
184
202
|
def >>: (Proc::_Callable g) -> Proc
|
|
185
203
|
|
|
@@ -191,6 +209,16 @@ class Method
|
|
|
191
209
|
# m.call(3) #=> 15
|
|
192
210
|
# m.call(20) #=> 32
|
|
193
211
|
#
|
|
212
|
+
# Using Method#=== allows a method object to be the target of a `when` clause in
|
|
213
|
+
# a case statement.
|
|
214
|
+
#
|
|
215
|
+
# require 'prime'
|
|
216
|
+
#
|
|
217
|
+
# case 1373
|
|
218
|
+
# when Prime.method(:prime?)
|
|
219
|
+
# # ...
|
|
220
|
+
# end
|
|
221
|
+
#
|
|
194
222
|
alias [] call
|
|
195
223
|
|
|
196
224
|
# <!--
|
|
@@ -359,10 +387,18 @@ class Method
|
|
|
359
387
|
|
|
360
388
|
# <!--
|
|
361
389
|
# rdoc-file=proc.c
|
|
362
|
-
# - meth.source_location -> [String, Integer]
|
|
390
|
+
# - meth.source_location -> [String, Integer, Integer, Integer, Integer]
|
|
363
391
|
# -->
|
|
364
|
-
# Returns the
|
|
365
|
-
#
|
|
392
|
+
# Returns the location where the method was defined. The returned Array
|
|
393
|
+
# contains:
|
|
394
|
+
# (1) the Ruby source filename
|
|
395
|
+
# (2) the line number where the definition starts
|
|
396
|
+
# (3) the column number where the definition starts
|
|
397
|
+
# (4) the line number where the definition ends
|
|
398
|
+
# (5) the column number where the definitions ends
|
|
399
|
+
#
|
|
400
|
+
# This method will return `nil` if the method was not defined in Ruby (i.e.
|
|
401
|
+
# native).
|
|
366
402
|
#
|
|
367
403
|
def source_location: () -> [String, Integer]?
|
|
368
404
|
|
|
@@ -370,8 +406,8 @@ class Method
|
|
|
370
406
|
# rdoc-file=proc.c
|
|
371
407
|
# - meth.super_method -> method
|
|
372
408
|
# -->
|
|
373
|
-
# Returns a Method of superclass which would be called when super is used or
|
|
374
|
-
# if there is no method on superclass.
|
|
409
|
+
# Returns a `Method` of superclass which would be called when super is used or
|
|
410
|
+
# nil if there is no method on superclass.
|
|
375
411
|
#
|
|
376
412
|
def super_method: () -> Method?
|
|
377
413
|
|
data/core/module.rbs
CHANGED
|
@@ -114,12 +114,15 @@ class Module < Object
|
|
|
114
114
|
|
|
115
115
|
# <!--
|
|
116
116
|
# rdoc-file=object.c
|
|
117
|
-
# -
|
|
117
|
+
# - self < other -> true, false, or nil
|
|
118
118
|
# -->
|
|
119
|
-
# Returns
|
|
120
|
-
#
|
|
121
|
-
#
|
|
122
|
-
#
|
|
119
|
+
# Returns whether `self` is a subclass of `other`, or `nil` if there is no
|
|
120
|
+
# relationship between the two:
|
|
121
|
+
#
|
|
122
|
+
# Float < Numeric # => true
|
|
123
|
+
# Numeric < Float # => false
|
|
124
|
+
# Float < Float # => false
|
|
125
|
+
# Float < Hash # => nil
|
|
123
126
|
#
|
|
124
127
|
def <: (Module other) -> bool?
|
|
125
128
|
|
|
@@ -135,14 +138,29 @@ class Module < Object
|
|
|
135
138
|
|
|
136
139
|
# <!--
|
|
137
140
|
# rdoc-file=object.c
|
|
138
|
-
# -
|
|
141
|
+
# - self <=> other -> -1, 0, 1, or nil
|
|
139
142
|
# -->
|
|
140
|
-
#
|
|
141
|
-
#
|
|
142
|
-
#
|
|
143
|
+
# Compares `self` and `other`.
|
|
144
|
+
#
|
|
145
|
+
# Returns:
|
|
146
|
+
#
|
|
147
|
+
# * `-1`, if `self` includes `other`, if or `self` is a subclass of `other`.
|
|
148
|
+
# * `0`, if `self` and `other` are the same.
|
|
149
|
+
# * `1`, if `other` includes `self`, or if `other` is a subclass of `self`.
|
|
150
|
+
# * `nil`, if none of the above is true.
|
|
151
|
+
#
|
|
152
|
+
# Examples:
|
|
143
153
|
#
|
|
144
|
-
#
|
|
145
|
-
#
|
|
154
|
+
# # Class Array includes module Enumerable.
|
|
155
|
+
# Array <=> Enumerable # => -1
|
|
156
|
+
# Enumerable <=> Enumerable # => 0
|
|
157
|
+
# Enumerable <=> Array # => 1
|
|
158
|
+
# # Class File is a subclass of class IO.
|
|
159
|
+
# File <=> IO # => -1
|
|
160
|
+
# File <=> File # => 0
|
|
161
|
+
# IO <=> File # => 1
|
|
162
|
+
# # Class File has no relationship to class String.
|
|
163
|
+
# File <=> String # => nil
|
|
146
164
|
#
|
|
147
165
|
def <=>: (untyped other) -> Integer?
|
|
148
166
|
|
|
@@ -328,6 +346,8 @@ class Module < Object
|
|
|
328
346
|
# replaced with *filename*. If *const* is defined but not as autoload, does
|
|
329
347
|
# nothing.
|
|
330
348
|
#
|
|
349
|
+
# Files that are currently being loaded must not be registered for autoload.
|
|
350
|
+
#
|
|
331
351
|
def autoload: (interned _module, String filename) -> NilClass
|
|
332
352
|
|
|
333
353
|
# <!--
|
|
@@ -487,6 +507,31 @@ class Module < Object
|
|
|
487
507
|
#
|
|
488
508
|
# Added :FOO
|
|
489
509
|
#
|
|
510
|
+
# If we define a class using the `class` keyword, `const_added` runs before
|
|
511
|
+
# `inherited`:
|
|
512
|
+
#
|
|
513
|
+
# module M
|
|
514
|
+
# def self.const_added(const_name)
|
|
515
|
+
# super
|
|
516
|
+
# p :const_added
|
|
517
|
+
# end
|
|
518
|
+
#
|
|
519
|
+
# parent = Class.new do
|
|
520
|
+
# def self.inherited(subclass)
|
|
521
|
+
# super
|
|
522
|
+
# p :inherited
|
|
523
|
+
# end
|
|
524
|
+
# end
|
|
525
|
+
#
|
|
526
|
+
# class Child < parent
|
|
527
|
+
# end
|
|
528
|
+
# end
|
|
529
|
+
#
|
|
530
|
+
# *produces:*
|
|
531
|
+
#
|
|
532
|
+
# :const_added
|
|
533
|
+
# :inherited
|
|
534
|
+
#
|
|
490
535
|
def const_added: (Symbol) -> void
|
|
491
536
|
|
|
492
537
|
# <!--
|
|
@@ -753,8 +798,6 @@ class Module < Object
|
|
|
753
798
|
#
|
|
754
799
|
def deprecate_constant: (*interned) -> self
|
|
755
800
|
|
|
756
|
-
def eql?: (untyped other) -> bool
|
|
757
|
-
|
|
758
801
|
def equal?: (untyped other) -> bool
|
|
759
802
|
|
|
760
803
|
# <!--
|
|
@@ -1321,19 +1364,52 @@ class Module < Object
|
|
|
1321
1364
|
# - protected(method_name, method_name, ...) -> array
|
|
1322
1365
|
# - protected(array) -> array
|
|
1323
1366
|
# -->
|
|
1324
|
-
#
|
|
1325
|
-
#
|
|
1326
|
-
#
|
|
1327
|
-
#
|
|
1328
|
-
#
|
|
1329
|
-
#
|
|
1367
|
+
# Sets the visibility of a section or of a list of method names as protected.
|
|
1368
|
+
# Accepts no arguments, a splat of method names (symbols or strings) or an array
|
|
1369
|
+
# of method names. Returns the arguments that it received.
|
|
1370
|
+
#
|
|
1371
|
+
# ## Important difference between protected in other languages
|
|
1372
|
+
#
|
|
1373
|
+
# Protected methods in Ruby are different from other languages such as Java,
|
|
1374
|
+
# where methods are marked as protected to give access to subclasses. In Ruby,
|
|
1375
|
+
# subclasses **already have access to all methods defined in the parent class**,
|
|
1376
|
+
# even private ones.
|
|
1377
|
+
#
|
|
1378
|
+
# Marking a method as protected allows **different objects of the same class**
|
|
1379
|
+
# to call it.
|
|
1380
|
+
#
|
|
1381
|
+
# One use case is for comparison methods, such as `==`, if we want to expose a
|
|
1382
|
+
# method for comparison between objects of the same class without making the
|
|
1383
|
+
# method public to objects of other classes.
|
|
1384
|
+
#
|
|
1385
|
+
# ## Performance considerations
|
|
1386
|
+
#
|
|
1387
|
+
# Protected methods are slower than others because they can't use inline cache.
|
|
1388
|
+
#
|
|
1389
|
+
# ## Example
|
|
1390
|
+
#
|
|
1391
|
+
# class Account
|
|
1392
|
+
# # Mark balance as protected, so that we can compare between accounts
|
|
1393
|
+
# # without making it public.
|
|
1394
|
+
# attr_reader :balance
|
|
1395
|
+
# protected :balance
|
|
1396
|
+
#
|
|
1397
|
+
# def initialize(balance)
|
|
1398
|
+
# @balance = balance
|
|
1399
|
+
# end
|
|
1400
|
+
#
|
|
1401
|
+
# def >(other)
|
|
1402
|
+
# # The invocation to `other.balance` is allowed because `other` is a
|
|
1403
|
+
# # different object of the same class (Account).
|
|
1404
|
+
# balance > other.balance
|
|
1405
|
+
# end
|
|
1406
|
+
# end
|
|
1330
1407
|
#
|
|
1331
|
-
#
|
|
1332
|
-
#
|
|
1333
|
-
# behavior is different from Java's protected method. Usually `private` should
|
|
1334
|
-
# be used.
|
|
1408
|
+
# account1 = Account.new(100)
|
|
1409
|
+
# account2 = Account.new(50)
|
|
1335
1410
|
#
|
|
1336
|
-
#
|
|
1411
|
+
# account1 > account2 # => true (works)
|
|
1412
|
+
# account1.balance # => NoMethodError (fails because balance is not public)
|
|
1337
1413
|
#
|
|
1338
1414
|
# To show a private method on RDoc, use `:doc:` instead of this.
|
|
1339
1415
|
#
|
|
@@ -1578,7 +1654,7 @@ class Module < Object
|
|
|
1578
1654
|
# m.name #=> nil
|
|
1579
1655
|
#
|
|
1580
1656
|
# c = Class.new
|
|
1581
|
-
# c.set_temporary_name("MyClass(with description)")
|
|
1657
|
+
# c.set_temporary_name("MyClass(with description)") # => MyClass(with description)
|
|
1582
1658
|
#
|
|
1583
1659
|
# c.new # => #<MyClass(with description):0x0....>
|
|
1584
1660
|
#
|
|
@@ -1696,7 +1772,8 @@ class Module < Object
|
|
|
1696
1772
|
# `attr_reader(name)` but deprecated. Returns an array of defined method names
|
|
1697
1773
|
# as symbols.
|
|
1698
1774
|
#
|
|
1699
|
-
def attr: (
|
|
1775
|
+
def attr: %a{deprecated} (interned, bool) -> Array[Symbol]
|
|
1776
|
+
| (*interned arg0) -> Array[Symbol]
|
|
1700
1777
|
|
|
1701
1778
|
# A previous incarnation of `interned` for backward-compatibility (see #1499)
|
|
1702
1779
|
%a{deprecated: Use `interned`}
|
data/core/nil_class.rbs
CHANGED
|
@@ -112,7 +112,7 @@ class NilClass
|
|
|
112
112
|
def nil?: () -> true
|
|
113
113
|
|
|
114
114
|
# <!--
|
|
115
|
-
# rdoc-file=
|
|
115
|
+
# rdoc-file=nilclass.rb
|
|
116
116
|
# - rationalize(eps = nil) -> (0/1)
|
|
117
117
|
# -->
|
|
118
118
|
# Returns zero as a Rational:
|
|
@@ -134,7 +134,7 @@ class NilClass
|
|
|
134
134
|
def to_a: () -> []
|
|
135
135
|
|
|
136
136
|
# <!--
|
|
137
|
-
# rdoc-file=
|
|
137
|
+
# rdoc-file=nilclass.rb
|
|
138
138
|
# - to_c -> (0+0i)
|
|
139
139
|
# -->
|
|
140
140
|
# Returns zero as a Complex:
|
|
@@ -174,7 +174,7 @@ class NilClass
|
|
|
174
174
|
def to_i: () -> 0
|
|
175
175
|
|
|
176
176
|
# <!--
|
|
177
|
-
# rdoc-file=
|
|
177
|
+
# rdoc-file=nilclass.rb
|
|
178
178
|
# - to_r -> (0/1)
|
|
179
179
|
# -->
|
|
180
180
|
# Returns zero as a Rational:
|
data/core/numeric.rbs
CHANGED
|
@@ -160,7 +160,7 @@ class Numeric
|
|
|
160
160
|
# rdoc-file=numeric.c
|
|
161
161
|
# - self % other -> real_numeric
|
|
162
162
|
# -->
|
|
163
|
-
# Returns `self` modulo `other` as a real
|
|
163
|
+
# Returns `self` modulo `other` as a real numeric (Integer, Float, or Rational).
|
|
164
164
|
#
|
|
165
165
|
# Of the Core and Standard Library classes, only Rational uses this
|
|
166
166
|
# implementation.
|
|
@@ -201,7 +201,7 @@ class Numeric
|
|
|
201
201
|
# -->
|
|
202
202
|
# Returns `self`.
|
|
203
203
|
#
|
|
204
|
-
def +@: () ->
|
|
204
|
+
def +@: () -> self
|
|
205
205
|
|
|
206
206
|
# Performs subtraction: the class of the resulting object depends on the class
|
|
207
207
|
# of `numeric`.
|
|
@@ -212,15 +212,23 @@ class Numeric
|
|
|
212
212
|
# rdoc-file=numeric.c
|
|
213
213
|
# - -self -> numeric
|
|
214
214
|
# -->
|
|
215
|
-
#
|
|
215
|
+
# Returns `self`, negated.
|
|
216
216
|
#
|
|
217
|
-
def -@: () ->
|
|
217
|
+
def -@: () -> self
|
|
218
218
|
|
|
219
219
|
# <!--
|
|
220
220
|
# rdoc-file=numeric.c
|
|
221
221
|
# - self <=> other -> zero or nil
|
|
222
222
|
# -->
|
|
223
|
-
#
|
|
223
|
+
# Compares `self` and `other`.
|
|
224
|
+
#
|
|
225
|
+
# Returns:
|
|
226
|
+
#
|
|
227
|
+
# * Zero, if `self` is the same as `other`.
|
|
228
|
+
# * `nil`, otherwise.
|
|
229
|
+
#
|
|
230
|
+
# Class Numeric includes module Comparable, each of whose methods uses
|
|
231
|
+
# Numeric#<=> for comparison.
|
|
224
232
|
#
|
|
225
233
|
# No subclass in the Ruby Core or Standard Library uses this implementation.
|
|
226
234
|
#
|
|
@@ -244,12 +252,12 @@ class Numeric
|
|
|
244
252
|
# -->
|
|
245
253
|
# Returns the square of `self`.
|
|
246
254
|
#
|
|
247
|
-
def abs2: () ->
|
|
255
|
+
def abs2: () -> self
|
|
248
256
|
|
|
249
257
|
# <!-- rdoc-file=complex.c -->
|
|
250
258
|
# Returns zero if `self` is positive, Math::PI otherwise.
|
|
251
259
|
#
|
|
252
|
-
def angle: () ->
|
|
260
|
+
def angle: () -> (0 | Float)
|
|
253
261
|
|
|
254
262
|
# <!--
|
|
255
263
|
# rdoc-file=complex.c
|
|
@@ -310,18 +318,18 @@ class Numeric
|
|
|
310
318
|
|
|
311
319
|
# <!--
|
|
312
320
|
# rdoc-file=numeric.rb
|
|
313
|
-
# - conj
|
|
321
|
+
# - conj -> self
|
|
314
322
|
# -->
|
|
323
|
+
# Returns `self`.
|
|
315
324
|
#
|
|
316
|
-
def
|
|
325
|
+
def conjugate: () -> self
|
|
317
326
|
|
|
318
327
|
# <!--
|
|
319
328
|
# rdoc-file=numeric.rb
|
|
320
|
-
# - conj
|
|
329
|
+
# - conj()
|
|
321
330
|
# -->
|
|
322
|
-
# Returns `self`.
|
|
323
331
|
#
|
|
324
|
-
|
|
332
|
+
alias conj conjugate
|
|
325
333
|
|
|
326
334
|
# <!--
|
|
327
335
|
# rdoc-file=rational.c
|
|
@@ -336,7 +344,7 @@ class Numeric
|
|
|
336
344
|
# - div(other) -> integer
|
|
337
345
|
# -->
|
|
338
346
|
# Returns the quotient `self/other` as an integer (via `floor`), using method
|
|
339
|
-
# `/` in the
|
|
347
|
+
# `/` as defined in the subclass of Numeric. (Numeric itself does not define
|
|
340
348
|
# `/`.)
|
|
341
349
|
#
|
|
342
350
|
# Of the Core and Standard Library classes, Only Float and Rational use this
|
|
@@ -398,8 +406,8 @@ class Numeric
|
|
|
398
406
|
# rdoc-file=numeric.c
|
|
399
407
|
# - fdiv(other) -> float
|
|
400
408
|
# -->
|
|
401
|
-
# Returns the quotient `self/other` as a float, using method `/`
|
|
402
|
-
#
|
|
409
|
+
# Returns the quotient `self/other` as a float, using method `/` as defined in
|
|
410
|
+
# the subclass of Numeric. (Numeric itself does not define `/`.)
|
|
403
411
|
#
|
|
404
412
|
# Of the Core and Standard Library classes, only BigDecimal uses this
|
|
405
413
|
# implementation.
|
|
@@ -445,18 +453,18 @@ class Numeric
|
|
|
445
453
|
|
|
446
454
|
# <!--
|
|
447
455
|
# rdoc-file=numeric.rb
|
|
448
|
-
# - imag
|
|
456
|
+
# - imag -> 0
|
|
449
457
|
# -->
|
|
458
|
+
# Returns zero.
|
|
450
459
|
#
|
|
451
|
-
def
|
|
460
|
+
def imaginary: () -> 0
|
|
452
461
|
|
|
453
462
|
# <!--
|
|
454
463
|
# rdoc-file=numeric.rb
|
|
455
|
-
# - imag
|
|
464
|
+
# - imag()
|
|
456
465
|
# -->
|
|
457
|
-
# Returns zero.
|
|
458
466
|
#
|
|
459
|
-
|
|
467
|
+
alias imag imaginary
|
|
460
468
|
|
|
461
469
|
# <!--
|
|
462
470
|
# rdoc-file=numeric.rb
|
|
@@ -488,7 +496,7 @@ class Numeric
|
|
|
488
496
|
alias magnitude abs
|
|
489
497
|
|
|
490
498
|
# <!-- rdoc-file=numeric.c -->
|
|
491
|
-
# Returns `self` modulo `other` as a real
|
|
499
|
+
# Returns `self` modulo `other` as a real numeric (Integer, Float, or Rational).
|
|
492
500
|
#
|
|
493
501
|
# Of the Core and Standard Library classes, only Rational uses this
|
|
494
502
|
# implementation.
|
|
@@ -530,17 +538,17 @@ class Numeric
|
|
|
530
538
|
# rdoc-file=numeric.c
|
|
531
539
|
# - nonzero? -> self or nil
|
|
532
540
|
# -->
|
|
533
|
-
# Returns
|
|
534
|
-
#
|
|
541
|
+
# Returns `self` if `self` is not a zero value, `nil` otherwise; uses method
|
|
542
|
+
# `zero?` for the evaluation.
|
|
535
543
|
#
|
|
536
|
-
#
|
|
544
|
+
# The returned `self` allows the method to be chained:
|
|
537
545
|
#
|
|
538
|
-
#
|
|
539
|
-
#
|
|
540
|
-
#
|
|
546
|
+
# a = %w[z Bb bB bb BB a aA Aa AA A]
|
|
547
|
+
# a.sort {|a, b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
|
|
548
|
+
# # => ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
|
|
541
549
|
#
|
|
542
|
-
#
|
|
543
|
-
#
|
|
550
|
+
# Of the Core and Standard Library classes, Integer, Float, Rational, and
|
|
551
|
+
# Complex use this implementation.
|
|
544
552
|
#
|
|
545
553
|
# Related: #zero?
|
|
546
554
|
#
|
|
@@ -590,7 +598,7 @@ class Numeric
|
|
|
590
598
|
# -->
|
|
591
599
|
# Returns `self`.
|
|
592
600
|
#
|
|
593
|
-
def real: () ->
|
|
601
|
+
def real: () -> self
|
|
594
602
|
|
|
595
603
|
# <!--
|
|
596
604
|
# rdoc-file=numeric.rb
|
|
@@ -598,7 +606,7 @@ class Numeric
|
|
|
598
606
|
# -->
|
|
599
607
|
# Returns `true` if `self` is a real number (i.e. not Complex).
|
|
600
608
|
#
|
|
601
|
-
def real?: () ->
|
|
609
|
+
def real?: () -> true
|
|
602
610
|
|
|
603
611
|
# <!-- rdoc-file=complex.c -->
|
|
604
612
|
# Returns array `[self, 0]`.
|
|
@@ -749,9 +757,9 @@ class Numeric
|
|
|
749
757
|
# where *n = (limit - self)/step*.
|
|
750
758
|
#
|
|
751
759
|
def step: (?Numeric limit, ?Numeric step) { (Numeric) -> void } -> self
|
|
752
|
-
| (?Numeric limit, ?Numeric step) -> Enumerator
|
|
760
|
+
| (?Numeric limit, ?Numeric step) -> Enumerator::ArithmeticSequence
|
|
753
761
|
| (?by: Numeric, ?to: Numeric) { (Numeric) -> void } -> self
|
|
754
|
-
| (?by: Numeric, ?to: Numeric) -> Enumerator
|
|
762
|
+
| (?by: Numeric, ?to: Numeric) -> Enumerator::ArithmeticSequence
|
|
755
763
|
|
|
756
764
|
# <!--
|
|
757
765
|
# rdoc-file=complex.c
|
|
@@ -765,8 +773,8 @@ class Numeric
|
|
|
765
773
|
# rdoc-file=numeric.c
|
|
766
774
|
# - to_int -> integer
|
|
767
775
|
# -->
|
|
768
|
-
# Returns `self` as an integer; converts using method `to_i` in the
|
|
769
|
-
#
|
|
776
|
+
# Returns `self` as an integer; converts using method `to_i` in the subclass of
|
|
777
|
+
# Numeric. (Numeric itself does not define `to_i`.)
|
|
770
778
|
#
|
|
771
779
|
# Of the Core and Standard Library classes, only Rational and Complex use this
|
|
772
780
|
# implementation.
|
data/core/object.rbs
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
# * #instance_of?: Returns whether `self` is an instance of the given class.
|
|
41
41
|
# * #instance_variable_defined?: Returns whether the given instance variable
|
|
42
42
|
# is defined in `self`.
|
|
43
|
-
# * #method: Returns the Method object for the given method in `self`.
|
|
43
|
+
# * #method: Returns the `Method` object for the given method in `self`.
|
|
44
44
|
# * #methods: Returns an array of symbol names of public and protected methods
|
|
45
45
|
# in `self`.
|
|
46
46
|
# * #nil?: Returns `false`. (Only `nil` responds `true` to method `nil?`.)
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
# methods in `self`.
|
|
51
51
|
# * #protected_methods: Returns an array of the symbol names of the protected
|
|
52
52
|
# methods in `self`.
|
|
53
|
-
# * #public_method: Returns the Method object for the given public method in
|
|
53
|
+
# * #public_method: Returns the `Method` object for the given public method in
|
|
54
54
|
# `self`.
|
|
55
55
|
# * #public_methods: Returns an array of the symbol names of the public
|
|
56
56
|
# methods in `self`.
|
|
57
57
|
# * #respond_to?: Returns whether `self` responds to the given method.
|
|
58
58
|
# * #singleton_class: Returns the singleton class of `self`.
|
|
59
|
-
# * #singleton_method: Returns the Method object for the given singleton
|
|
59
|
+
# * #singleton_method: Returns the `Method` object for the given singleton
|
|
60
60
|
# method in `self`.
|
|
61
61
|
# * #singleton_methods: Returns an array of the symbol names of the singleton
|
|
62
62
|
# methods in `self`.
|
data/core/object_space.rbs
CHANGED
|
@@ -29,6 +29,7 @@ module ObjectSpace
|
|
|
29
29
|
# - _id2ref(p1)
|
|
30
30
|
# -->
|
|
31
31
|
#
|
|
32
|
+
%a{deprecated}
|
|
32
33
|
def self._id2ref: (Integer id) -> untyped
|
|
33
34
|
|
|
34
35
|
# <!--
|
|
@@ -136,28 +137,33 @@ module ObjectSpace
|
|
|
136
137
|
# Calls the block once for each living, nonimmediate object in this Ruby
|
|
137
138
|
# process. If *module* is specified, calls the block for only those classes or
|
|
138
139
|
# modules that match (or are a subclass of) *module*. Returns the number of
|
|
139
|
-
# objects found. Immediate objects (`Fixnum`s, `Symbol`s `true`,
|
|
140
|
-
# `nil`) are never returned.
|
|
141
|
-
# numbers we defined and several constants defined in the Math module.
|
|
140
|
+
# objects found. Immediate objects (such as `Fixnum`s, static `Symbol`s `true`,
|
|
141
|
+
# `false` and `nil`) are never returned.
|
|
142
142
|
#
|
|
143
143
|
# If no block is given, an enumerator is returned instead.
|
|
144
144
|
#
|
|
145
|
-
#
|
|
146
|
-
#
|
|
147
|
-
#
|
|
148
|
-
# count = ObjectSpace.each_object(Numeric) {|x| p x }
|
|
145
|
+
# Job = Class.new
|
|
146
|
+
# jobs = [Job.new, Job.new]
|
|
147
|
+
# count = ObjectSpace.each_object(Job) {|x| p x }
|
|
149
148
|
# puts "Total count: #{count}"
|
|
150
149
|
#
|
|
151
150
|
# *produces:*
|
|
152
151
|
#
|
|
153
|
-
#
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
#
|
|
157
|
-
#
|
|
158
|
-
#
|
|
159
|
-
#
|
|
160
|
-
#
|
|
152
|
+
# #<Job:0x000000011d6cbbf0>
|
|
153
|
+
# #<Job:0x000000011d6cbc68>
|
|
154
|
+
# Total count: 2
|
|
155
|
+
#
|
|
156
|
+
# Due to a current Ractor implementation issue, this method does not yield
|
|
157
|
+
# Ractor-unshareable objects when the process is in multi-Ractor mode.
|
|
158
|
+
# Multi-ractor mode is enabled when `Ractor.new` has been called for the first
|
|
159
|
+
# time. See https://bugs.ruby-lang.org/issues/19387 for more information.
|
|
160
|
+
#
|
|
161
|
+
# a = 12345678987654321 # shareable
|
|
162
|
+
# b = [].freeze # shareable
|
|
163
|
+
# c = {} # not shareable
|
|
164
|
+
# ObjectSpace.each_object {|x| x } # yields a, b, and c
|
|
165
|
+
# Ractor.new {} # enter multi-Ractor mode
|
|
166
|
+
# ObjectSpace.each_object {|x| x } # does not yield c
|
|
161
167
|
#
|
|
162
168
|
def self.each_object: (?Module `module`) -> Enumerator[untyped, Integer]
|
|
163
169
|
| (?Module `module`) { (untyped obj) -> void } -> Integer
|