rbs 3.8.0.pre.1 → 3.8.0

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.
data/core/nil_class.rbs CHANGED
@@ -18,6 +18,9 @@
18
18
  # * #to_r
19
19
  # * #to_s
20
20
  #
21
+ # While `nil` doesn't have an explicitly defined #to_hash method, it can be used
22
+ # in `**` unpacking, not adding any keyword arguments.
23
+ #
21
24
  # Another method provides inspection:
22
25
  #
23
26
  # * #inspect
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) # Raises RangeError (non-zero imaginary part)
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
- # ## Numbered parameters
239
+ # ## Anonymous block parameters
240
240
  #
241
- # Numbered parameters are implicitly defined block parameters intended to
242
- # simplify writing short blocks:
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
- # # Implicit parameter:
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 a warning.
338
+ # so on, causes an error.
267
339
  #
268
- # _1 = 'test'
269
- # # warning: `_1' is reserved as numbered parameter
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
- # # SyntaxError (numbered parameter is already used in outer block here)
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
- # Punctation:
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
  #
@@ -83,7 +83,9 @@
83
83
  #
84
84
  # ## License
85
85
  #
86
- # See [LICENSE.txt](rdoc-ref:lib/rubygems/LICENSE.txt) for permissions.
86
+ # See
87
+ # [LICENSE.txt](https://github.com/rubygems/rubygems/blob/master/LICENSE.txt)
88
+ # for permissions.
87
89
  #
88
90
  # Thanks!
89
91
  #
@@ -83,7 +83,9 @@
83
83
  #
84
84
  # ## License
85
85
  #
86
- # See [LICENSE.txt](rdoc-ref:lib/rubygems/LICENSE.txt) for permissions.
86
+ # See
87
+ # [LICENSE.txt](https://github.com/rubygems/rubygems/blob/master/LICENSE.txt)
88
+ # for permissions.
87
89
  #
88
90
  # Thanks!
89
91
  #