rbs 3.3.2 → 3.4.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -5
  3. data/.github/workflows/ruby.yml +7 -8
  4. data/.github/workflows/typecheck.yml +37 -0
  5. data/CHANGELOG.md +50 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +11 -11
  8. data/Steepfile +2 -2
  9. data/core/array.rbs +19 -49
  10. data/core/basic_object.rbs +2 -2
  11. data/core/comparable.rbs +17 -8
  12. data/core/complex.rbs +82 -43
  13. data/core/data.rbs +2 -4
  14. data/core/dir.rbs +635 -295
  15. data/core/enumerable.rbs +11 -18
  16. data/core/enumerator.rbs +37 -31
  17. data/core/errors.rbs +4 -0
  18. data/core/false_class.rbs +34 -15
  19. data/core/fiber.rbs +23 -0
  20. data/core/file.rbs +329 -120
  21. data/core/float.rbs +17 -32
  22. data/core/gc.rbs +17 -11
  23. data/core/hash.rbs +22 -44
  24. data/core/integer.rbs +82 -113
  25. data/core/io/buffer.rbs +90 -47
  26. data/core/io.rbs +39 -116
  27. data/core/kernel.rbs +442 -489
  28. data/core/match_data.rbs +55 -56
  29. data/core/module.rbs +45 -1
  30. data/core/nil_class.rbs +98 -35
  31. data/core/numeric.rbs +22 -32
  32. data/core/object_space/weak_key_map.rbs +102 -0
  33. data/core/process.rbs +1242 -655
  34. data/core/ractor.rbs +139 -120
  35. data/core/range.rbs +100 -4
  36. data/core/rational.rbs +0 -4
  37. data/core/rbs/unnamed/argf.rbs +16 -8
  38. data/core/rbs/unnamed/env_class.rbs +0 -24
  39. data/core/refinement.rbs +8 -0
  40. data/core/regexp.rbs +1149 -598
  41. data/core/ruby_vm.rbs +126 -12
  42. data/core/rubygems/platform.rbs +9 -0
  43. data/core/rubygems/rubygems.rbs +1 -1
  44. data/core/rubygems/version.rbs +5 -1
  45. data/core/set.rbs +20 -22
  46. data/core/signal.rbs +4 -4
  47. data/core/string.rbs +283 -230
  48. data/core/string_io.rbs +2 -14
  49. data/core/struct.rbs +404 -24
  50. data/core/symbol.rbs +1 -19
  51. data/core/thread.rbs +29 -12
  52. data/core/time.rbs +227 -104
  53. data/core/trace_point.rbs +2 -5
  54. data/core/true_class.rbs +54 -21
  55. data/core/warning.rbs +14 -11
  56. data/docs/data_and_struct.md +29 -0
  57. data/docs/syntax.md +3 -5
  58. data/docs/tools.md +1 -0
  59. data/ext/rbs_extension/lexer.c +643 -559
  60. data/ext/rbs_extension/lexer.re +5 -1
  61. data/ext/rbs_extension/parser.c +12 -3
  62. data/ext/rbs_extension/unescape.c +7 -47
  63. data/lib/rbs/cli/diff.rb +4 -1
  64. data/lib/rbs/cli/validate.rb +280 -0
  65. data/lib/rbs/cli.rb +2 -194
  66. data/lib/rbs/collection/config.rb +5 -6
  67. data/lib/rbs/collection/sources/git.rb +1 -1
  68. data/lib/rbs/collection.rb +1 -0
  69. data/lib/rbs/diff.rb +7 -4
  70. data/lib/rbs/errors.rb +11 -0
  71. data/lib/rbs/test/errors.rb +4 -1
  72. data/lib/rbs/test/guaranteed.rb +2 -3
  73. data/lib/rbs/test/type_check.rb +15 -10
  74. data/lib/rbs/test.rb +3 -3
  75. data/lib/rbs/types.rb +29 -0
  76. data/lib/rbs/unit_test/convertibles.rb +176 -0
  77. data/lib/rbs/unit_test/spy.rb +136 -0
  78. data/lib/rbs/unit_test/type_assertions.rb +341 -0
  79. data/lib/rbs/unit_test/with_aliases.rb +143 -0
  80. data/lib/rbs/unit_test.rb +6 -0
  81. data/lib/rbs/version.rb +1 -1
  82. data/sig/cli/validate.rbs +43 -0
  83. data/sig/diff.rbs +3 -1
  84. data/sig/errors.rbs +8 -0
  85. data/sig/rbs.rbs +1 -1
  86. data/sig/test/errors.rbs +52 -0
  87. data/sig/test/guranteed.rbs +9 -0
  88. data/sig/test/type_check.rbs +19 -0
  89. data/sig/test.rbs +82 -0
  90. data/sig/types.rbs +6 -1
  91. data/sig/unit_test/convertibles.rbs +154 -0
  92. data/sig/unit_test/spy.rbs +28 -0
  93. data/sig/unit_test/type_assertions.rbs +194 -0
  94. data/sig/unit_test/with_aliases.rbs +136 -0
  95. data/stdlib/base64/0/base64.rbs +307 -45
  96. data/stdlib/bigdecimal/0/big_decimal.rbs +35 -15
  97. data/stdlib/coverage/0/coverage.rbs +2 -2
  98. data/stdlib/csv/0/csv.rbs +25 -55
  99. data/stdlib/date/0/date.rbs +1 -43
  100. data/stdlib/date/0/date_time.rbs +1 -13
  101. data/stdlib/delegate/0/delegator.rbs +186 -0
  102. data/stdlib/delegate/0/kernel.rbs +47 -0
  103. data/stdlib/delegate/0/simple_delegator.rbs +98 -0
  104. data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -1
  105. data/stdlib/erb/0/erb.rbs +2 -2
  106. data/stdlib/fileutils/0/fileutils.rbs +0 -19
  107. data/stdlib/io-console/0/io-console.rbs +12 -1
  108. data/stdlib/ipaddr/0/ipaddr.rbs +2 -1
  109. data/stdlib/json/0/json.rbs +320 -81
  110. data/stdlib/logger/0/logger.rbs +9 -5
  111. data/stdlib/monitor/0/monitor.rbs +78 -0
  112. data/stdlib/net-http/0/net-http.rbs +1880 -543
  113. data/stdlib/objspace/0/objspace.rbs +19 -13
  114. data/stdlib/openssl/0/openssl.rbs +508 -127
  115. data/stdlib/optparse/0/optparse.rbs +25 -11
  116. data/stdlib/pathname/0/pathname.rbs +1 -1
  117. data/stdlib/pp/0/pp.rbs +2 -5
  118. data/stdlib/prettyprint/0/prettyprint.rbs +2 -2
  119. data/stdlib/pstore/0/pstore.rbs +2 -4
  120. data/stdlib/rdoc/0/comment.rbs +1 -2
  121. data/stdlib/resolv/0/resolv.rbs +4 -2
  122. data/stdlib/socket/0/socket.rbs +2 -2
  123. data/stdlib/socket/0/unix_socket.rbs +2 -2
  124. data/stdlib/strscan/0/string_scanner.rbs +3 -2
  125. data/stdlib/tempfile/0/tempfile.rbs +1 -1
  126. data/stdlib/uri/0/common.rbs +245 -123
  127. metadata +23 -4
  128. data/lib/rbs/test/spy.rb +0 -6
data/core/range.rbs CHANGED
@@ -176,6 +176,8 @@
176
176
  # * [Comparing](rdoc-ref:Range@Methods+for+Comparing)
177
177
  # * [Iterating](rdoc-ref:Range@Methods+for+Iterating)
178
178
  # * [Converting](rdoc-ref:Range@Methods+for+Converting)
179
+ # * [Methods for Working with
180
+ # JSON](rdoc-ref:Range@Methods+for+Working+with+JSON)
179
181
  #
180
182
  #
181
183
  # ### Methods for Creating a Range
@@ -225,6 +227,19 @@
225
227
  # * #to_a (aliased as #entries): Returns elements of `self` in an array.
226
228
  # * #to_s: Returns a string representation of `self` (uses #to_s).
227
229
  #
230
+ #
231
+ # ### Methods for Working with JSON
232
+ #
233
+ # * ::json_create: Returns a new Range object constructed from the given
234
+ # object.
235
+ # * #as_json: Returns a 2-element hash representing `self`.
236
+ # * #to_json: Returns a JSON string representing `self`.
237
+ #
238
+ #
239
+ # To make these methods available:
240
+ #
241
+ # require 'json/add/range'
242
+ #
228
243
  class Range[out Elem] < Object
229
244
  include Enumerable[Elem]
230
245
 
@@ -556,8 +571,6 @@ class Range[out Elem] < Object
556
571
  #
557
572
  # Related: Range#cover?.
558
573
  #
559
- # Range#member? is an alias for Range#include?.
560
- #
561
574
  def include?: (untyped obj) -> bool
562
575
 
563
576
  # <!--
@@ -808,6 +821,91 @@ class Range[out Elem] < Object
808
821
  | (Integer n) -> ::Array[Elem]
809
822
  | (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
810
823
 
824
+ # <!--
825
+ # rdoc-file=range.c
826
+ # - overlap?(range) -> true or false
827
+ # -->
828
+ # Returns `true` if `range` overlaps with `self`, `false` otherwise:
829
+ #
830
+ # (0..2).overlap?(1..3) #=> true
831
+ # (0..2).overlap?(3..4) #=> false
832
+ # (0..).overlap?(..0) #=> true
833
+ #
834
+ # With non-range argument, raises TypeError.
835
+ #
836
+ # (1..3).overlap?(1) # TypeError
837
+ #
838
+ # Returns `false` if an internal call to `<=>` returns `nil`; that is, the
839
+ # operands are not comparable.
840
+ #
841
+ # (1..3).overlap?('a'..'d') # => false
842
+ #
843
+ # Returns `false` if `self` or `range` is empty. "Empty range" means that its
844
+ # begin value is larger than, or equal for an exclusive range, its end value.
845
+ #
846
+ # (4..1).overlap?(2..3) # => false
847
+ # (4..1).overlap?(..3) # => false
848
+ # (4..1).overlap?(2..) # => false
849
+ # (2...2).overlap?(1..2) # => false
850
+ #
851
+ # (1..4).overlap?(3..2) # => false
852
+ # (..4).overlap?(3..2) # => false
853
+ # (1..).overlap?(3..2) # => false
854
+ # (1..2).overlap?(2...2) # => false
855
+ #
856
+ # Returns `false` if the begin value one of `self` and `range` is larger than,
857
+ # or equal if the other is an exclusive range, the end value of the other:
858
+ #
859
+ # (4..5).overlap?(2..3) # => false
860
+ # (4..5).overlap?(2...4) # => false
861
+ #
862
+ # (1..2).overlap?(3..4) # => false
863
+ # (1...3).overlap?(3..4) # => false
864
+ #
865
+ # Returns `false` if the end value one of `self` and `range` is larger than, or
866
+ # equal for an exclusive range, the end value of the other:
867
+ #
868
+ # (4..5).overlap?(2..3) # => false
869
+ # (4..5).overlap?(2...4) # => false
870
+ #
871
+ # (1..2).overlap?(3..4) # => false
872
+ # (1...3).overlap?(3..4) # => false
873
+ #
874
+ # This method assumes that there is no minimum value because Ruby lacks a
875
+ # standard method for determining minimum values. This assumption is invalid.
876
+ # For example, there is no value smaller than `-Float::INFINITY`, making
877
+ # `(...-Float::INFINITY)` an empty set. Consequently, `(...-Float::INFINITY)`
878
+ # has no elements in common with itself, yet
879
+ # `(...-Float::INFINITY).overlap?((...-Float::INFINITY))<tt> returns true due to
880
+ # this assumption. In general, if <tt>r = (...minimum); r.overlap?(r)` returns
881
+ # `true`, where `minimum` is a value that no value is smaller than. Such values
882
+ # include `-Float::INFINITY`, `[]`, `""`, and classes without subclasses.
883
+ #
884
+ # Related: Range#cover?.
885
+ #
886
+ def overlap?: (Range[untyped]) -> bool
887
+
888
+ # <!--
889
+ # rdoc-file=range.c
890
+ # - reverse_each {|element| ... } -> self
891
+ # - reverse_each -> an_enumerator
892
+ # -->
893
+ # With a block given, passes each element of `self` to the block in reverse
894
+ # order:
895
+ #
896
+ # a = []
897
+ # (1..4).reverse_each {|element| a.push(element) } # => 1..4
898
+ # a # => [4, 3, 2, 1]
899
+ #
900
+ # a = []
901
+ # (1...4).reverse_each {|element| a.push(element) } # => 1...4
902
+ # a # => [3, 2, 1]
903
+ #
904
+ # With no block given, returns an enumerator.
905
+ #
906
+ def reverse_each: () { (Elem) -> void } -> self
907
+ | () -> ::Enumerator[Elem, self]
908
+
811
909
  # <!--
812
910
  # rdoc-file=range.c
813
911
  # - size -> non_negative_integer or Infinity or nil
@@ -947,7 +1045,5 @@ class Range[out Elem] < Object
947
1045
  #
948
1046
  # Related: Range#cover?.
949
1047
  #
950
- # Range#member? is an alias for Range#include?.
951
- #
952
1048
  def member?: (untyped obj) -> bool
953
1049
  end
data/core/rational.rbs CHANGED
@@ -190,8 +190,6 @@ class Rational < Numeric
190
190
  # (1/2r).abs #=> (1/2)
191
191
  # (-1/2r).abs #=> (1/2)
192
192
  #
193
- # Rational#magnitude is an alias for Rational#abs.
194
- #
195
193
  def abs: () -> Rational
196
194
 
197
195
  def abs2: () -> Rational
@@ -328,8 +326,6 @@ class Rational < Numeric
328
326
  # (1/2r).abs #=> (1/2)
329
327
  # (-1/2r).abs #=> (1/2)
330
328
  #
331
- # Rational#magnitude is an alias for Rational#abs.
332
- #
333
329
  alias magnitude abs
334
330
 
335
331
  def modulo: (Float) -> Float
@@ -31,12 +31,16 @@ module RBS
31
31
  # ARGV.replace ["file2", "file3"]
32
32
  # ARGF.read # Returns the contents of file2 and file3
33
33
  #
34
- # If `ARGV` is empty, ARGF acts as if it contained STDIN, i.e. the data piped to
35
- # your script. For example:
34
+ # If `ARGV` is empty, ARGF acts as if it contained `"-"` that makes ARGF read
35
+ # from STDIN, i.e. the data piped or typed to your script. For example:
36
36
  #
37
37
  # $ echo "glark" | ruby -e 'p ARGF.read'
38
38
  # "glark\n"
39
39
  #
40
+ # $ echo Glark > file1
41
+ # $ echo "glark" | ruby -e 'p ARGF.read' -- - file1
42
+ # "glark\nGlark\n"
43
+ #
40
44
  %a{annotate:rdoc:copy:ARGF}
41
45
  class ARGFClass
42
46
  include Enumerable[String]
@@ -825,12 +829,12 @@ module RBS
825
829
 
826
830
  # <!--
827
831
  # rdoc-file=io.c
828
- # - ARGF.readlines(sep = $/) -> array
829
- # - ARGF.readlines(limit) -> array
830
- # - ARGF.readlines(sep, limit) -> array
831
- # - ARGF.to_a(sep = $/) -> array
832
- # - ARGF.to_a(limit) -> array
833
- # - ARGF.to_a(sep, limit) -> array
832
+ # - ARGF.readlines(sep = $/, chomp: false) -> array
833
+ # - ARGF.readlines(limit, chomp: false) -> array
834
+ # - ARGF.readlines(sep, limit, chomp: false) -> array
835
+ # - ARGF.to_a(sep = $/, chomp: false) -> array
836
+ # - ARGF.to_a(limit, chomp: false) -> array
837
+ # - ARGF.to_a(sep, limit, chomp: false) -> array
834
838
  # -->
835
839
  # Reads each file in ARGF in its entirety, returning an Array containing lines
836
840
  # from the files. Lines are assumed to be separated by *sep*.
@@ -838,6 +842,8 @@ module RBS
838
842
  # lines = ARGF.readlines
839
843
  # lines[0] #=> "This is line one\n"
840
844
  #
845
+ # See `IO.readlines` for a full description of all options.
846
+ #
841
847
  %a{annotate:rdoc:copy:ARGF#readlines}
842
848
  def readlines: (?String sep, ?Integer limit) -> ::Array[String]
843
849
 
@@ -956,6 +962,8 @@ module RBS
956
962
  # lines = ARGF.readlines
957
963
  # lines[0] #=> "This is line one\n"
958
964
  #
965
+ # See `IO.readlines` for a full description of all options.
966
+ #
959
967
  %a{annotate:rdoc:copy:ARGF#to_a}
960
968
  def to_a: (?String sep, ?Integer limit) -> ::Array[String]
961
969
 
@@ -239,8 +239,6 @@ module RBS
239
239
  # - ENV[name] = value -> value
240
240
  # - ENV.store(name, value) -> value
241
241
  # -->
242
- # ENV.store is an alias for ENV.[]=.
243
- #
244
242
  # Creates, updates, or deletes the named environment variable, returning the
245
243
  # value. Both `name` and `value` may be instances of String. See [Valid Names
246
244
  # and Values](rdoc-ref:ENV@Valid+Names+and+Values).
@@ -294,8 +292,6 @@ module RBS
294
292
  # - ENV[name] = value -> value
295
293
  # - ENV.store(name, value) -> value
296
294
  # -->
297
- # ENV.store is an alias for ENV.[]=.
298
- #
299
295
  # Creates, updates, or deletes the named environment variable, returning the
300
296
  # value. Both `name` and `value` may be instances of String. See [Valid Names
301
297
  # and Values](rdoc-ref:ENV@Valid+Names+and+Values).
@@ -601,8 +597,6 @@ module RBS
601
597
  # - ENV.filter { |name, value| block } -> hash of name/value pairs
602
598
  # - ENV.filter -> an_enumerator
603
599
  # -->
604
- # ENV.filter is an alias for ENV.select.
605
- #
606
600
  # Yields each environment variable name and its value as a 2-element Array,
607
601
  # returning a Hash of the names and values for which the block returns a truthy
608
602
  # value:
@@ -627,8 +621,6 @@ module RBS
627
621
  # - ENV.filter { |name, value| block } -> hash of name/value pairs
628
622
  # - ENV.filter -> an_enumerator
629
623
  # -->
630
- # ENV.filter is an alias for ENV.select.
631
- #
632
624
  # Yields each environment variable name and its value as a 2-element Array,
633
625
  # returning a Hash of the names and values for which the block returns a truthy
634
626
  # value:
@@ -652,8 +644,6 @@ module RBS
652
644
  # - ENV.filter! { |name, value| block } -> ENV or nil
653
645
  # - ENV.filter! -> an_enumerator
654
646
  # -->
655
- # ENV.filter! is an alias for ENV.select!.
656
- #
657
647
  # Yields each environment variable name and its value as a 2-element Array,
658
648
  # deleting each entry for which the block returns `false` or `nil`, and
659
649
  # returning ENV if any deletions made, or `nil` otherwise:
@@ -693,8 +683,6 @@ module RBS
693
683
  # - ENV.filter! { |name, value| block } -> ENV or nil
694
684
  # - ENV.filter! -> an_enumerator
695
685
  # -->
696
- # ENV.filter! is an alias for ENV.select!.
697
- #
698
686
  # Yields each environment variable name and its value as a 2-element Array,
699
687
  # deleting each entry for which the block returns `false` or `nil`, and
700
688
  # returning ENV if any deletions made, or `nil` otherwise:
@@ -794,8 +782,6 @@ module RBS
794
782
  # - ENV.merge!(*hashes) -> ENV
795
783
  # - ENV.merge!(*hashes) { |name, env_val, hash_val| block } -> ENV
796
784
  # -->
797
- # ENV.update is an alias for ENV.merge!.
798
- #
799
785
  # Adds to ENV each key/value pair in the given `hash`; returns ENV:
800
786
  # ENV.replace('foo' => '0', 'bar' => '1')
801
787
  # ENV.merge!('baz' => '2', 'bat' => '3') # => {"bar"=>"1", "bat"=>"3", "baz"=>"2", "foo"=>"0"}
@@ -839,8 +825,6 @@ module RBS
839
825
  # - ENV.merge!(*hashes) -> ENV
840
826
  # - ENV.merge!(*hashes) { |name, env_val, hash_val| block } -> ENV
841
827
  # -->
842
- # ENV.update is an alias for ENV.merge!.
843
- #
844
828
  # Adds to ENV each key/value pair in the given `hash`; returns ENV:
845
829
  # ENV.replace('foo' => '0', 'bar' => '1')
846
830
  # ENV.merge!('baz' => '2', 'bat' => '3') # => {"bar"=>"1", "bat"=>"3", "baz"=>"2", "foo"=>"0"}
@@ -1026,8 +1010,6 @@ module RBS
1026
1010
  # - ENV.member?(name) -> true or false
1027
1011
  # - ENV.key?(name) -> true or false
1028
1012
  # -->
1029
- # ENV.has_key?, ENV.member?, and ENV.key? are aliases for ENV.include?.
1030
- #
1031
1013
  # Returns `true` if there is an environment variable with the given `name`:
1032
1014
  # ENV.replace('foo' => '0', 'bar' => '1')
1033
1015
  # ENV.include?('foo') # => true
@@ -1061,8 +1043,6 @@ module RBS
1061
1043
  # - ENV.member?(name) -> true or false
1062
1044
  # - ENV.key?(name) -> true or false
1063
1045
  # -->
1064
- # ENV.has_key?, ENV.member?, and ENV.key? are aliases for ENV.include?.
1065
- #
1066
1046
  # Returns `true` if there is an environment variable with the given `name`:
1067
1047
  # ENV.replace('foo' => '0', 'bar' => '1')
1068
1048
  # ENV.include?('foo') # => true
@@ -1096,8 +1076,6 @@ module RBS
1096
1076
  # - ENV.member?(name) -> true or false
1097
1077
  # - ENV.key?(name) -> true or false
1098
1078
  # -->
1099
- # ENV.has_key?, ENV.member?, and ENV.key? are aliases for ENV.include?.
1100
- #
1101
1079
  # Returns `true` if there is an environment variable with the given `name`:
1102
1080
  # ENV.replace('foo' => '0', 'bar' => '1')
1103
1081
  # ENV.include?('foo') # => true
@@ -1163,8 +1141,6 @@ module RBS
1163
1141
  # - ENV.member?(name) -> true or false
1164
1142
  # - ENV.key?(name) -> true or false
1165
1143
  # -->
1166
- # ENV.has_key?, ENV.member?, and ENV.key? are aliases for ENV.include?.
1167
- #
1168
1144
  # Returns `true` if there is an environment variable with the given `name`:
1169
1145
  # ENV.replace('foo' => '0', 'bar' => '1')
1170
1146
  # ENV.include?('foo') # => true
data/core/refinement.rbs CHANGED
@@ -49,4 +49,12 @@ class Refinement < Module
49
49
  # Return the class refined by the receiver.
50
50
  #
51
51
  def refined_class: () -> Module
52
+
53
+ # <!--
54
+ # rdoc-file=eval.c
55
+ # - target -> class
56
+ # -->
57
+ # Return the class or module refined by the receiver.
58
+ #
59
+ def target: () -> Module
52
60
  end