rbs 3.8.0.pre.1 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +1 -1
- data/CHANGELOG.md +16 -0
- data/core/array.rbs +64 -62
- data/core/complex.rbs +1 -1
- data/core/encoding.rbs +0 -26
- data/core/errors.rbs +4 -0
- data/core/exception.rbs +2 -2
- data/core/file.rbs +1 -8
- data/core/gc.rbs +20 -2
- data/core/hash.rbs +2 -2
- data/core/io.rbs +2 -2
- data/core/kernel.rbs +2 -2
- data/core/nil_class.rbs +3 -0
- data/core/numeric.rbs +1 -1
- data/core/proc.rbs +80 -10
- data/core/ractor.rbs +17 -0
- data/core/regexp.rbs +2 -2
- data/core/ruby_vm.rbs +1 -1
- data/core/rubygems/errors.rbs +3 -1
- data/core/rubygems/rubygems.rbs +3 -1
- data/core/string.rbs +132 -130
- data/core/time.rbs +4 -0
- data/core/trace_point.rbs +108 -113
- data/ext/rbs_extension/parser.c +1 -1
- data/lib/rbs/types.rb +2 -1
- data/lib/rbs/version.rb +1 -1
- data/stdlib/date/0/date.rbs +23 -23
- data/stdlib/net-http/0/net-http.rbs +20 -29
- data/stdlib/rdoc/0/rdoc.rbs +12 -6
- data/stdlib/resolv/0/resolv.rbs +5 -1
- data/stdlib/securerandom/0/securerandom.rbs +7 -0
- data/stdlib/socket/0/socket.rbs +9 -28
- data/stdlib/socket/0/tcp_socket.rbs +8 -30
- data/stdlib/tmpdir/0/tmpdir.rbs +2 -2
- metadata +3 -4
data/core/nil_class.rbs
CHANGED
data/core/numeric.rbs
CHANGED
@@ -776,7 +776,7 @@ class Numeric
|
|
776
776
|
# Rational(1, 2).to_int # => 0
|
777
777
|
# Rational(2, 1).to_int # => 2
|
778
778
|
# Complex(2, 0).to_int # => 2
|
779
|
-
# Complex(2, 1)
|
779
|
+
# Complex(2, 1).to_int # Raises RangeError (non-zero imaginary part)
|
780
780
|
#
|
781
781
|
def to_int: () -> Integer
|
782
782
|
|
data/core/proc.rbs
CHANGED
@@ -236,19 +236,86 @@
|
|
236
236
|
# Since `return` and `break` exits the block itself in lambdas, lambdas cannot
|
237
237
|
# be orphaned.
|
238
238
|
#
|
239
|
-
# ##
|
239
|
+
# ## Anonymous block parameters
|
240
240
|
#
|
241
|
-
#
|
242
|
-
#
|
241
|
+
# To simplify writing short blocks, Ruby provides two different types of
|
242
|
+
# anonymous parameters: `it` (single parameter) and numbered ones: `_1`, `_2`
|
243
|
+
# and so on.
|
243
244
|
#
|
244
245
|
# # Explicit parameter:
|
245
246
|
# %w[test me please].each { |str| puts str.upcase } # prints TEST, ME, PLEASE
|
246
247
|
# (1..5).map { |i| i**2 } # => [1, 4, 9, 16, 25]
|
247
248
|
#
|
248
|
-
# #
|
249
|
+
# # it:
|
250
|
+
# %w[test me please].each { puts it.upcase } # prints TEST, ME, PLEASE
|
251
|
+
# (1..5).map { it**2 } # => [1, 4, 9, 16, 25]
|
252
|
+
#
|
253
|
+
# # Numbered parameter:
|
249
254
|
# %w[test me please].each { puts _1.upcase } # prints TEST, ME, PLEASE
|
250
255
|
# (1..5).map { _1**2 } # => [1, 4, 9, 16, 25]
|
251
256
|
#
|
257
|
+
# ### `it`
|
258
|
+
#
|
259
|
+
# `it` is a name that is available inside a block when no explicit parameters
|
260
|
+
# defined, as shown above.
|
261
|
+
#
|
262
|
+
# %w[test me please].each { puts it.upcase } # prints TEST, ME, PLEASE
|
263
|
+
# (1..5).map { it**2 } # => [1, 4, 9, 16, 25]
|
264
|
+
#
|
265
|
+
# `it` is a "soft keyword": it is not a reserved name, and can be used as a name
|
266
|
+
# for methods and local variables:
|
267
|
+
#
|
268
|
+
# it = 5 # no warnings
|
269
|
+
# def it(&block) # RSpec-like API, no warnings
|
270
|
+
# # ...
|
271
|
+
# end
|
272
|
+
#
|
273
|
+
# `it` can be used as a local variable even in blocks that use it as an implicit
|
274
|
+
# parameter (though this style is obviously confusing):
|
275
|
+
#
|
276
|
+
# [1, 2, 3].each {
|
277
|
+
# # takes a value of implicit parameter "it" and uses it to
|
278
|
+
# # define a local variable with the same name
|
279
|
+
# it = it**2
|
280
|
+
# p it
|
281
|
+
# }
|
282
|
+
#
|
283
|
+
# In a block with explicit parameters defined `it` usage raises an exception:
|
284
|
+
#
|
285
|
+
# [1, 2, 3].each { |x| p it }
|
286
|
+
# # syntax error found (SyntaxError)
|
287
|
+
# # [1, 2, 3].each { |x| p it }
|
288
|
+
# # ^~ `it` is not allowed when an ordinary parameter is defined
|
289
|
+
#
|
290
|
+
# But if a local name (variable or method) is available, it would be used:
|
291
|
+
#
|
292
|
+
# it = 5
|
293
|
+
# [1, 2, 3].each { |x| p it }
|
294
|
+
# # Prints 5, 5, 5
|
295
|
+
#
|
296
|
+
# Blocks using `it` can be nested:
|
297
|
+
#
|
298
|
+
# %w[test me].each { it.each_char { p it } }
|
299
|
+
# # Prints "t", "e", "s", "t", "m", "e"
|
300
|
+
#
|
301
|
+
# Blocks using `it` are considered to have one parameter:
|
302
|
+
#
|
303
|
+
# p = proc { it**2 }
|
304
|
+
# l = lambda { it**2 }
|
305
|
+
# p.parameters # => [[:opt, nil]]
|
306
|
+
# p.arity # => 1
|
307
|
+
# l.parameters # => [[:req]]
|
308
|
+
# l.arity # => 1
|
309
|
+
#
|
310
|
+
# ### Numbered parameters
|
311
|
+
#
|
312
|
+
# Numbered parameters are another way to name block parameters implicitly.
|
313
|
+
# Unlike `it`, numbered parameters allow to refer to several parameters in one
|
314
|
+
# block.
|
315
|
+
#
|
316
|
+
# %w[test me please].each { puts _1.upcase } # prints TEST, ME, PLEASE
|
317
|
+
# {a: 100, b: 200}.map { "#{_1} = #{_2}" } # => "a = 100", "b = 200"
|
318
|
+
#
|
252
319
|
# Parameter names from `_1` to `_9` are supported:
|
253
320
|
#
|
254
321
|
# [10, 20, 30].zip([40, 50, 60], [70, 80, 90]).map { _1 + _2 + _3 }
|
@@ -262,11 +329,16 @@
|
|
262
329
|
# [10, 20, 30].map { |x| _1**2 }
|
263
330
|
# # SyntaxError (ordinary parameter is defined)
|
264
331
|
#
|
332
|
+
# Numbered parameters can't be mixed with `it` either:
|
333
|
+
#
|
334
|
+
# [10, 20, 30].map { _1 + it }
|
335
|
+
# # SyntaxError: `it` is not allowed when a numbered parameter is already used
|
336
|
+
#
|
265
337
|
# To avoid conflicts, naming local variables or method arguments `_1`, `_2` and
|
266
|
-
# so on, causes
|
338
|
+
# so on, causes an error.
|
267
339
|
#
|
268
|
-
#
|
269
|
-
# #
|
340
|
+
# _1 = 'test'
|
341
|
+
# # ^~ _1 is reserved for numbered parameters (SyntaxError)
|
270
342
|
#
|
271
343
|
# Using implicit numbered parameters affects block's arity:
|
272
344
|
#
|
@@ -280,12 +352,10 @@
|
|
280
352
|
# Blocks with numbered parameters can't be nested:
|
281
353
|
#
|
282
354
|
# %w[test me].each { _1.each_char { p _1 } }
|
283
|
-
# #
|
355
|
+
# # numbered parameter is already used in outer block (SyntaxError)
|
284
356
|
# # %w[test me].each { _1.each_char { p _1 } }
|
285
357
|
# # ^~
|
286
358
|
#
|
287
|
-
# Numbered parameters were introduced in Ruby 2.7.
|
288
|
-
#
|
289
359
|
class Proc
|
290
360
|
interface _Callable
|
291
361
|
def call: (?) -> untyped
|
data/core/ractor.rbs
CHANGED
@@ -588,6 +588,23 @@ class Ractor
|
|
588
588
|
#
|
589
589
|
def self.shareable?: (untyped obj) -> bool
|
590
590
|
|
591
|
+
# <!--
|
592
|
+
# rdoc-file=ractor.rb
|
593
|
+
# - Ractor.store_if_absent(key){ init_block }
|
594
|
+
# -->
|
595
|
+
# If the correponding value is not set, yield a value with init_block and store
|
596
|
+
# the value in thread-safe manner. This method returns corresponding stored
|
597
|
+
# value.
|
598
|
+
#
|
599
|
+
# (1..10).map{
|
600
|
+
# Thread.new(it){|i|
|
601
|
+
# Ractor.store_if_absent(:s){ f(); i }
|
602
|
+
# #=> return stored value of key :s
|
603
|
+
# }
|
604
|
+
# }.map(&:value).uniq.size #=> 1 and f() is called only once
|
605
|
+
#
|
606
|
+
def self.store_if_absent: (Symbol) { () -> untyped } -> untyped
|
607
|
+
|
591
608
|
# <!--
|
592
609
|
# rdoc-file=ractor.rb
|
593
610
|
# - Ractor.yield(msg, move: false) -> nil
|
data/core/regexp.rbs
CHANGED
@@ -897,7 +897,7 @@
|
|
897
897
|
# * [Nl, Letter_Number](https://www.compart.com/en/unicode/category/Nl).
|
898
898
|
# * [No, Other_Number](https://www.compart.com/en/unicode/category/No).
|
899
899
|
#
|
900
|
-
#
|
900
|
+
# Punctuation:
|
901
901
|
#
|
902
902
|
# * `P`, `Punctuation`: `Pc`, `Pd`, `Pe`, `Pf`, `Pi`, `Po`, or `Ps`.
|
903
903
|
# * [Pc,
|
@@ -1603,7 +1603,7 @@ class Regexp
|
|
1603
1603
|
# `self`:
|
1604
1604
|
#
|
1605
1605
|
# * Is a regexp literal; see [Regexp
|
1606
|
-
# Literals](rdoc-ref:literals.rdoc@Regexp+Literals).
|
1606
|
+
# Literals](rdoc-ref:syntax/literals.rdoc@Regexp+Literals).
|
1607
1607
|
# * Does not contain interpolations; see [Regexp
|
1608
1608
|
# interpolation](rdoc-ref:Regexp@Interpolation+Mode).
|
1609
1609
|
# * Is at the left of the expression.
|
data/core/ruby_vm.rbs
CHANGED
@@ -591,7 +591,7 @@ module RubyVM::AbstractSyntaxTree
|
|
591
591
|
|
592
592
|
# <!-- rdoc-file=ast.rb -->
|
593
593
|
# RubyVM::AbstractSyntaxTree::Location instances are created by
|
594
|
-
# RubyVM::AbstractSyntaxTree#locations.
|
594
|
+
# RubyVM::AbstractSyntaxTree::Node#locations.
|
595
595
|
#
|
596
596
|
# This class is MRI specific.
|
597
597
|
#
|
data/core/rubygems/errors.rbs
CHANGED
data/core/rubygems/rubygems.rbs
CHANGED