rbs 3.3.1 → 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 +56 -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/string.rbs CHANGED
@@ -81,7 +81,7 @@
81
81
  # * `\k<name>` refers to the named capture `name`.
82
82
  #
83
83
  #
84
- # See regexp.rdoc for details.
84
+ # See Regexp for details.
85
85
  #
86
86
  # Note that within the string `replacement`, a character combination such as
87
87
  # `$&` is treated as ordinary text, and not as a special match variable.
@@ -92,10 +92,10 @@
92
92
  # text.
93
93
  # * `\'` corresponds to `$'`, which contains string after match.
94
94
  # * `\`` corresponds to `$``, which contains string before match.
95
- # * `+` corresponds to `$+`, which contains last capture group.
95
+ # * `\+` corresponds to `$+`, which contains last capture group.
96
96
  #
97
97
  #
98
- # See regexp.rdoc for details.
98
+ # See Regexp for details.
99
99
  #
100
100
  # Note that `\\\` is interpreted as an escape, i.e., a single backslash.
101
101
  #
@@ -279,7 +279,7 @@
279
279
  #
280
280
  # If argument `capture` is given and not `0`, it should be either an capture
281
281
  # group index (integer) or a capture group name (string or symbol); the slice is
282
- # the specified capture (see Regexp@Capturing):
282
+ # the specified capture (see Regexp@Groups+and+Captures):
283
283
  #
284
284
  # s = 'hello there'
285
285
  # s[/[aeiou](.)\1/, 1] # => "l"
@@ -629,6 +629,9 @@
629
629
  class String
630
630
  include Comparable
631
631
 
632
+ # A `selector` is a special type of string, used within methods like `String#tr`.
633
+ type selector = string
634
+
632
635
  # <!--
633
636
  # rdoc-file=string.c
634
637
  # - String.try_convert(object) -> object, new_string, or nil
@@ -642,9 +645,76 @@ class String
642
645
  #
643
646
  # Raises an exception unless `object.to_str` returns a String object.
644
647
  #
645
- def self.try_convert: (untyped obj) -> String?
648
+ def self.try_convert: (String object) -> String # technically will return `object` unchanged.
649
+ | (_ToStr object) -> String
650
+ | (untyped object) -> String?
651
+
652
+ # <!--
653
+ # rdoc-file=string.c
654
+ # - String.new(string = '', **opts) -> new_string
655
+ # -->
656
+ # Returns a new String that is a copy of `string`.
657
+ #
658
+ # With no arguments, returns the empty string with the Encoding `ASCII-8BIT`:
659
+ #
660
+ # s = String.new
661
+ # s # => ""
662
+ # s.encoding # => #<Encoding:ASCII-8BIT>
663
+ #
664
+ # With optional argument `string` and no keyword arguments, returns a copy of
665
+ # `string` with the same encoding:
666
+ #
667
+ # String.new('foo') # => "foo"
668
+ # String.new('тест') # => "тест"
669
+ # String.new('こんにちは') # => "こんにちは"
670
+ #
671
+ # (Unlike String.new, a [string
672
+ # literal](rdoc-ref:syntax/literals.rdoc@String+Literals) like `''` or a [here
673
+ # document literal](rdoc-ref:syntax/literals.rdoc@Here+Document+Literals) always
674
+ # has [script encoding](rdoc-ref:encodings.rdoc@Script+Encoding).)
675
+ #
676
+ # With optional keyword argument `encoding`, returns a copy of `string` with the
677
+ # specified encoding; the `encoding` may be an Encoding object, an encoding
678
+ # name, or an encoding name alias:
679
+ #
680
+ # String.new('foo', encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII>
681
+ # String.new('foo', encoding: 'US-ASCII').encoding # => #<Encoding:US-ASCII>
682
+ # String.new('foo', encoding: 'ASCII').encoding # => #<Encoding:US-ASCII>
683
+ #
684
+ # The given encoding need not be valid for the string's content, and that
685
+ # validity is not checked:
686
+ #
687
+ # s = String.new('こんにちは', encoding: 'ascii')
688
+ # s.valid_encoding? # => false
689
+ #
690
+ # But the given `encoding` itself is checked:
691
+ #
692
+ # String.new('foo', encoding: 'bar') # Raises ArgumentError.
693
+ #
694
+ # With optional keyword argument `capacity`, returns a copy of `string` (or an
695
+ # empty string, if `string` is not given); the given `capacity` is advisory
696
+ # only, and may or may not set the size of the internal buffer, which may in
697
+ # turn affect performance:
698
+ #
699
+ # String.new(capacity: 1)
700
+ # String.new('foo', capacity: 4096)
701
+ #
702
+ # The `string`, `encoding`, and `capacity` arguments may all be used together:
703
+ #
704
+ # String.new('hello', encoding: 'UTF-8', capacity: 25)
705
+ #
706
+ def initialize: (?string source, ?encoding: encoding?, ?capacity: int?) -> self
646
707
 
647
- public
708
+ # <!--
709
+ # rdoc-file=string.c
710
+ # - replace(other_string) -> self
711
+ # -->
712
+ # Replaces the contents of `self` with the contents of `other_string`:
713
+ #
714
+ # s = 'foo' # => "foo"
715
+ # s.replace('bar') # => "bar"
716
+ #
717
+ alias initialize_copy replace
648
718
 
649
719
  # <!--
650
720
  # rdoc-file=string.c
@@ -662,8 +732,8 @@ class String
662
732
  # "foo = %{foo}" % {foo: 'bar'} # => "foo = bar"
663
733
  # "foo = %{foo}, baz = %{baz}" % {foo: 'bar', baz: 'bat'} # => "foo = bar, baz = bat"
664
734
  #
665
- def %: (Hash[Symbol, untyped]) -> String
666
- | (Array[untyped]) -> String
735
+ def %: (array[untyped] positional_args) -> String
736
+ | (hash[Symbol, untyped] named_args) -> String
667
737
  | (untyped arg) -> String
668
738
 
669
739
  # <!--
@@ -675,7 +745,7 @@ class String
675
745
  # "Ho! " * 3 # => "Ho! Ho! Ho! "
676
746
  # "Ho! " * 0 # => ""
677
747
  #
678
- def *: (int n) -> String
748
+ def *: (int amount) -> String
679
749
 
680
750
  # <!--
681
751
  # rdoc-file=string.c
@@ -685,7 +755,7 @@ class String
685
755
  #
686
756
  # "Hello from " + self.to_s # => "Hello from main"
687
757
  #
688
- def +: (string other_str) -> String
758
+ def +: (string other_string) -> String
689
759
 
690
760
  # <!--
691
761
  # rdoc-file=string.c
@@ -695,20 +765,28 @@ class String
695
765
  #
696
766
  # Otherwise returns `self.dup`, which is not frozen.
697
767
  #
698
- def +@: () -> String
768
+ def +@: () -> self
699
769
 
700
770
  # <!--
701
771
  # rdoc-file=string.c
702
772
  # - -string -> frozen_string
773
+ # - dedup -> frozen_string
703
774
  # -->
704
775
  # Returns a frozen, possibly pre-existing copy of the string.
705
776
  #
706
777
  # The returned String will be deduplicated as long as it does not have any
707
778
  # instance variables set on it and is not a String subclass.
708
779
  #
709
- # String#dedup is an alias for String#-@.
780
+ # Note that `-string` variant is more convenient for defining constants:
781
+ #
782
+ # FILENAME = -'config/database.yml'
783
+ #
784
+ # while `dedup` is better suitable for using the method in chains of
785
+ # calculations:
786
+ #
787
+ # @url_list.concat(urls.map(&:dedup))
710
788
  #
711
- def -@: () -> String
789
+ def -@: () -> self
712
790
 
713
791
  # <!--
714
792
  # rdoc-file=string.c
@@ -728,7 +806,7 @@ class String
728
806
  #
729
807
  # Related: String#concat, which takes multiple arguments.
730
808
  #
731
- def <<: (string | Integer str_or_codepoint) -> String
809
+ def <<: (string | Integer str_or_codepoint) -> self
732
810
 
733
811
  # <!--
734
812
  # rdoc-file=string.c
@@ -751,8 +829,8 @@ class String
751
829
  # 'foo' <=> 'FOO' # => 1
752
830
  # 'foo' <=> 1 # => nil
753
831
  #
754
- def <=>: (string other) -> Integer
755
- | (untyped other) -> Integer?
832
+ def <=>: (string) -> (-1 | 0 | 1)
833
+ | (untyped) -> (-1 | 0 | 1)?
756
834
 
757
835
  # <!--
758
836
  # rdoc-file=string.c
@@ -773,7 +851,7 @@ class String
773
851
  # If `object` is not an instance of String but responds to `to_str`, then the
774
852
  # two strings are compared using `object.==`.
775
853
  #
776
- def ==: (untyped obj) -> bool
854
+ def ==: (untyped other) -> bool
777
855
 
778
856
  # <!-- rdoc-file=string.c -->
779
857
  # Returns `true` if `object` has the same length and content; as `self`; `false`
@@ -790,7 +868,7 @@ class String
790
868
  # If `object` is not an instance of String but responds to `to_str`, then the
791
869
  # two strings are compared using `object.==`.
792
870
  #
793
- def ===: (untyped obj) -> bool
871
+ alias === ==
794
872
 
795
873
  # <!--
796
874
  # rdoc-file=string.c
@@ -804,7 +882,7 @@ class String
804
882
  # 'foo' =~ /o/ # => 1
805
883
  # 'foo' =~ /x/ # => nil
806
884
  #
807
- # Note: also updates Regexp@Special+global+variables.
885
+ # Note: also updates Regexp@Global+Variables.
808
886
  #
809
887
  # If the given `object` is not a Regexp, returns the value returned by `object
810
888
  # =~ self`.
@@ -818,7 +896,12 @@ class String
818
896
  # /(?<number>\d+)/ =~ "no. 9"
819
897
  # number #=> "9"
820
898
  #
821
- def =~: (untyped obj) -> Integer?
899
+ def =~: (Regexp regex) -> Integer?
900
+ | [T] (_MatchAgainst[self, T] object) -> T
901
+
902
+ interface _MatchAgainst[O, T]
903
+ def =~: (O string) -> T
904
+ end
822
905
 
823
906
  # <!--
824
907
  # rdoc-file=string.c
@@ -831,12 +914,10 @@ class String
831
914
  # Returns the substring of `self` specified by the arguments. See examples at
832
915
  # [String Slices](rdoc-ref:String@String+Slices).
833
916
  #
834
- def []: (int index) -> String?
835
- | (int start, int length) -> String?
836
- | (Range[Integer] | Range[Integer?] range) -> String?
837
- | (Regexp regexp) -> String?
838
- | (Regexp regexp, int | String capture) -> String?
839
- | (String match_str) -> String?
917
+ def []: (int start, ?int length) -> String?
918
+ | (range[int?] range) -> String?
919
+ | (Regexp regexp, ?MatchData::capture backref) -> String?
920
+ | (String substring) -> String?
840
921
 
841
922
  # <!--
842
923
  # rdoc-file=string.c
@@ -863,15 +944,12 @@ class String
863
944
  # s['lly'] = 'ncial' # => "ncial"
864
945
  # s # => "financial"
865
946
  #
866
- # String#slice is an alias for String#[].
867
- #
868
- def []=: (int pos, String new_str) -> String
869
- | (int begin_pos, int end_pos, String new_str) -> String
870
- | (Range[Integer] | Range[Integer?] range, String new_str) -> String
871
- | (Regexp regexp, String new_str) -> String
872
- | (Regexp regexp, int capture, String new_str) -> String
873
- | (Regexp regexp, String name, String new_str) -> String
874
- | (String other_str, String new_str) -> String
947
+ def []=: [T < _ToStr] (int index, T replacement) -> T
948
+ | [T < _ToStr] (int start, int length, T replacement) -> T
949
+ | [T < _ToStr] (range[int?] range, T replacement) -> T
950
+ | [T < _ToStr] (Regexp regexp, T replacement) -> T
951
+ | [T < _ToStr] (Regexp regexp, MatchData::capture backref, T replacement) -> T
952
+ | [T < _ToStr] (String substring, T replacement) -> T
875
953
 
876
954
  # <!--
877
955
  # rdoc-file=string.c
@@ -945,7 +1023,7 @@ class String
945
1023
  #
946
1024
  # Related: String#index, String#byterindex.
947
1025
  #
948
- def byteindex: (Regexp | string substr_or_regexp, ?int offset) -> Integer?
1026
+ def byteindex: (Regexp | string pattern, ?int offset) -> Integer?
949
1027
 
950
1028
  # <!--
951
1029
  # rdoc-file=string.c
@@ -1006,7 +1084,7 @@ class String
1006
1084
  #
1007
1085
  # Related: String#byteindex.
1008
1086
  #
1009
- def byterindex: (Regexp | string substr_or_regexp, ?int offset) -> Integer?
1087
+ def byterindex: (Regexp | string pattern, ?int offset) -> Integer?
1010
1088
 
1011
1089
  # <!--
1012
1090
  # rdoc-file=string.c
@@ -1020,7 +1098,7 @@ class String
1020
1098
  # # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
1021
1099
  #
1022
1100
  def bytes: () -> Array[Integer]
1023
- | () { (Integer byte) -> void } -> String
1101
+ | () { (Integer byte) -> void } -> self
1024
1102
 
1025
1103
  # <!--
1026
1104
  # rdoc-file=string.c
@@ -1082,24 +1160,34 @@ class String
1082
1160
  # s.byteslice(4).encoding # => #<Encoding:UTF-8>
1083
1161
  #
1084
1162
  def byteslice: (int start, ?int length) -> String?
1085
- | (Range[Integer] | Range[Integer?] range) -> String?
1163
+ | (range[int?] range) -> String?
1086
1164
 
1087
1165
  # <!--
1088
1166
  # rdoc-file=string.c
1089
1167
  # - bytesplice(index, length, str) -> string
1090
- # - bytesplice(range, str) -> string
1168
+ # - bytesplice(index, length, str, str_index, str_length) -> string
1169
+ # - bytesplice(range, str) -> string
1170
+ # - bytesplice(range, str, str_range) -> string
1091
1171
  # -->
1092
1172
  # Replaces some or all of the content of `self` with `str`, and returns `self`.
1093
1173
  # The portion of the string affected is determined using the same criteria as
1094
1174
  # String#byteslice, except that `length` cannot be omitted. If the replacement
1095
1175
  # string is not the same length as the text it is replacing, the string will be
1096
- # adjusted accordingly. The form that take an Integer will raise an IndexError
1097
- # if the value is out of range; the Range form will raise a RangeError. If the
1098
- # beginning or ending offset does not land on character (codepoint) boundary, an
1099
- # IndexError will be raised.
1176
+ # adjusted accordingly.
1177
+ #
1178
+ # If `str_index` and `str_length`, or `str_range` are given, the content of
1179
+ # `self` is replaced by str.byteslice(str_index, str_length) or
1180
+ # str.byteslice(str_range); however the substring of `str` is not allocated as a
1181
+ # new string.
1182
+ #
1183
+ # The form that take an Integer will raise an IndexError if the value is out of
1184
+ # range; the Range form will raise a RangeError. If the beginning or ending
1185
+ # offset does not land on character (codepoint) boundary, an IndexError will be
1186
+ # raised.
1100
1187
  #
1101
- def bytesplice: (int index, int length, string str) -> String
1102
- | (Range[int?], string str) -> String
1188
+ def bytesplice: (int start, int length, string str) -> String
1189
+ | (int start, int length, string str, int str_start, int str_length) -> String
1190
+ | (range[int?] range, string str, ?range[int?] str_range) -> String
1103
1191
 
1104
1192
  # <!--
1105
1193
  # rdoc-file=string.c
@@ -1138,10 +1226,10 @@ class String
1138
1226
  #
1139
1227
  # Related: String#capitalize.
1140
1228
  #
1141
- def capitalize!: () -> String?
1142
- | (:ascii | :lithuanian | :turkic) -> String?
1143
- | (:lithuanian, :turkic) -> String?
1144
- | (:turkic, :lithuanian) -> String?
1229
+ def capitalize!: () -> self?
1230
+ | (:ascii | :lithuanian | :turkic) -> self?
1231
+ | (:lithuanian, :turkic) -> self?
1232
+ | (:turkic, :lithuanian) -> self?
1145
1233
 
1146
1234
  # <!--
1147
1235
  # rdoc-file=string.c
@@ -1168,7 +1256,8 @@ class String
1168
1256
  #
1169
1257
  # Related: String#casecmp?.
1170
1258
  #
1171
- def casecmp: (untyped other) -> Integer?
1259
+ def casecmp: (string other) -> (-1 | 0 | 1)
1260
+ | (untyped) -> (-1 | 0 | 1)?
1172
1261
 
1173
1262
  # <!--
1174
1263
  # rdoc-file=string.c
@@ -1191,7 +1280,8 @@ class String
1191
1280
  #
1192
1281
  # Related: String#casecmp.
1193
1282
  #
1194
- def casecmp?: (untyped other) -> bool?
1283
+ def casecmp?: (string other) -> bool
1284
+ | (untyped) -> bool?
1195
1285
 
1196
1286
  # <!--
1197
1287
  # rdoc-file=string.c
@@ -1216,7 +1306,7 @@ class String
1216
1306
  #
1217
1307
  # Related: String#ljust, String#rjust.
1218
1308
  #
1219
- def center: (int width, ?string padstr) -> String
1309
+ def center: (int width, ?string pad_string) -> String
1220
1310
 
1221
1311
  # <!--
1222
1312
  # rdoc-file=string.c
@@ -1229,7 +1319,7 @@ class String
1229
1319
  # 'こんにちは'.chars # => ["こ", "ん", "に", "ち", "は"]
1230
1320
  #
1231
1321
  def chars: () -> Array[String]
1232
- | () { (String char) -> void } -> String
1322
+ | () { (String char) -> void } -> self
1233
1323
 
1234
1324
  # <!--
1235
1325
  # rdoc-file=string.c
@@ -1264,7 +1354,7 @@ class String
1264
1354
  # 'abcd'.chomp('d') # => "abc"
1265
1355
  # 'abcdd'.chomp('d') # => "abcd"
1266
1356
  #
1267
- def chomp: (?string separator) -> String
1357
+ def chomp: (?string? separator) -> String
1268
1358
 
1269
1359
  # <!--
1270
1360
  # rdoc-file=string.c
@@ -1273,7 +1363,9 @@ class String
1273
1363
  # Like String#chomp, but modifies `self` in place; returns `nil` if no
1274
1364
  # modification made, `self` otherwise.
1275
1365
  #
1276
- def chomp!: (?string separator) -> String?
1366
+ def chomp!: (nil) -> nil
1367
+ # | (?string separator) -> self? # https://github.com/ruby/rbs/pull/1672#discussion_r1423324796
1368
+ | (?string? separator) -> self?
1277
1369
 
1278
1370
  # <!--
1279
1371
  # rdoc-file=string.c
@@ -1309,7 +1401,7 @@ class String
1309
1401
  #
1310
1402
  # Related: String#chomp!.
1311
1403
  #
1312
- def chop!: () -> String?
1404
+ def chop!: () -> self?
1313
1405
 
1314
1406
  # <!--
1315
1407
  # rdoc-file=string.c
@@ -1331,7 +1423,7 @@ class String
1331
1423
  # s = 'foo' # => "foo"
1332
1424
  # s.clear # => ""
1333
1425
  #
1334
- def clear: () -> String
1426
+ def clear: () -> self
1335
1427
 
1336
1428
  # <!--
1337
1429
  # rdoc-file=string.c
@@ -1344,8 +1436,8 @@ class String
1344
1436
  # 'тест'.codepoints # => [1090, 1077, 1089, 1090]
1345
1437
  # 'こんにちは'.codepoints # => [12371, 12435, 12395, 12385, 12399]
1346
1438
  #
1347
- def codepoints: () -> ::Array[Integer]
1348
- | () { (Integer codepoint) -> void } -> String
1439
+ def codepoints: () -> Array[Integer]
1440
+ | () { (Integer codepoint) -> void } -> self
1349
1441
 
1350
1442
  # <!--
1351
1443
  # rdoc-file=string.c
@@ -1365,7 +1457,7 @@ class String
1365
1457
  #
1366
1458
  # Related: String#<<, which takes a single argument.
1367
1459
  #
1368
- def concat: (*string | Integer str_or_codepoint) -> String
1460
+ def concat: (*string | Integer string_or_codepoints) -> self
1369
1461
 
1370
1462
  # <!--
1371
1463
  # rdoc-file=string.c
@@ -1389,7 +1481,7 @@ class String
1389
1481
  # c.count "\\A" #=> 0
1390
1482
  # c.count "X-\\w" #=> 3
1391
1483
  #
1392
- def count: (string other_str, *string other_strs) -> Integer
1484
+ def count: (selector selector_0, *selector more_selectors) -> Integer
1393
1485
 
1394
1486
  # <!--
1395
1487
  # rdoc-file=string.c
@@ -1453,7 +1545,14 @@ class String
1453
1545
  # The returned String will be deduplicated as long as it does not have any
1454
1546
  # instance variables set on it and is not a String subclass.
1455
1547
  #
1456
- # String#dedup is an alias for String#-@.
1548
+ # Note that `-string` variant is more convenient for defining constants:
1549
+ #
1550
+ # FILENAME = -'config/database.yml'
1551
+ #
1552
+ # while `dedup` is better suitable for using the method in chains of
1553
+ # calculations:
1554
+ #
1555
+ # @url_list.concat(urls.map(&:dedup))
1457
1556
  #
1458
1557
  alias dedup -@
1459
1558
 
@@ -1470,7 +1569,7 @@ class String
1470
1569
  # "hello".delete "aeiou", "^e" #=> "hell"
1471
1570
  # "hello".delete "ej-m" #=> "ho"
1472
1571
  #
1473
- def delete: (string other_str, *string other_strs) -> String
1572
+ def delete: (selector selector_0, *selector more_selectors) -> String
1474
1573
 
1475
1574
  # <!--
1476
1575
  # rdoc-file=string.c
@@ -1479,7 +1578,7 @@ class String
1479
1578
  # Like String#delete, but modifies `self` in place. Returns `self` if any
1480
1579
  # changes were made, `nil` otherwise.
1481
1580
  #
1482
- def delete!: (string other_str, *string other_strs) -> String?
1581
+ def delete!: (selector selector_0, *selector more_selectors) -> self?
1483
1582
 
1484
1583
  # <!--
1485
1584
  # rdoc-file=string.c
@@ -1503,7 +1602,7 @@ class String
1503
1602
  # Like String#delete_prefix, except that `self` is modified in place. Returns
1504
1603
  # `self` if the prefix is removed, `nil` otherwise.
1505
1604
  #
1506
- def delete_prefix!: (string prefix) -> String?
1605
+ def delete_prefix!: (string prefix) -> self?
1507
1606
 
1508
1607
  # <!--
1509
1608
  # rdoc-file=string.c
@@ -1527,7 +1626,7 @@ class String
1527
1626
  # Like String#delete_suffix, except that `self` is modified in place. Returns
1528
1627
  # `self` if the suffix is removed, `nil` otherwise.
1529
1628
  #
1530
- def delete_suffix!: (string suffix) -> String?
1629
+ def delete_suffix!: (string suffix) -> self?
1531
1630
 
1532
1631
  # <!--
1533
1632
  # rdoc-file=string.c
@@ -1565,10 +1664,10 @@ class String
1565
1664
  #
1566
1665
  # Related: String#downcase, String#upcase, String#upcase!.
1567
1666
  #
1568
- def downcase!: () -> String?
1569
- | (:ascii | :fold | :lithuanian | :turkic) -> String?
1570
- | (:lithuanian, :turkic) -> String?
1571
- | (:turkic, :lithuanian) -> String?
1667
+ def downcase!: () -> self?
1668
+ | (:ascii | :fold | :lithuanian | :turkic) -> self?
1669
+ | (:lithuanian, :turkic) -> self?
1670
+ | (:turkic, :lithuanian) -> self?
1572
1671
 
1573
1672
  # <!--
1574
1673
  # rdoc-file=string.c
@@ -1607,8 +1706,8 @@ class String
1607
1706
  #
1608
1707
  # Returns an enumerator if no block is given.
1609
1708
  #
1610
- def each_byte: () { (Integer byte) -> void } -> self
1611
- | () -> ::Enumerator[Integer, self]
1709
+ def each_byte: () -> Enumerator[Integer, self]
1710
+ | () { (Integer byte) -> void } -> self
1612
1711
 
1613
1712
  # <!--
1614
1713
  # rdoc-file=string.c
@@ -1633,8 +1732,8 @@ class String
1633
1732
  #
1634
1733
  # Returns an enumerator if no block is given.
1635
1734
  #
1636
- def each_char: () { (String char) -> void } -> self
1637
- | () -> ::Enumerator[String, self]
1735
+ def each_char: () -> Enumerator[String, self]
1736
+ | () { (String char) -> void } -> self
1638
1737
 
1639
1738
  # <!--
1640
1739
  # rdoc-file=string.c
@@ -1659,8 +1758,8 @@ class String
1659
1758
  #
1660
1759
  # Returns an enumerator if no block is given.
1661
1760
  #
1662
- def each_codepoint: () { (Integer codepoint) -> void } -> self
1663
- | () -> ::Enumerator[Integer, self]
1761
+ def each_codepoint: () -> Enumerator[Integer, self]
1762
+ | () { (Integer codepoint) -> void } -> self
1664
1763
 
1665
1764
  # <!--
1666
1765
  # rdoc-file=string.c
@@ -1681,8 +1780,8 @@ class String
1681
1780
  #
1682
1781
  # Returns an enumerator if no block is given.
1683
1782
  #
1684
- def each_grapheme_cluster: () { (String grapheme) -> void } -> self
1685
- | () -> ::Enumerator[String, self]
1783
+ def each_grapheme_cluster: () -> Enumerator[String, self]
1784
+ | () { (String grapheme_cluter) -> void } -> self
1686
1785
 
1687
1786
  # <!--
1688
1787
  # rdoc-file=string.c
@@ -1747,8 +1846,8 @@ class String
1747
1846
  #
1748
1847
  # With no block given, returns an enumerator.
1749
1848
  #
1750
- def each_line: (?string separator, ?chomp: boolish) { (String line) -> void } -> self
1751
- | (?string separator, ?chomp: boolish) -> Enumerator[String, self]
1849
+ def each_line: (?string? separator, ?chomp: boolish) -> Enumerator[String, self]
1850
+ | (?string? separator, ?chomp: boolish) { (String line) -> void } -> self
1752
1851
 
1753
1852
  # <!--
1754
1853
  # rdoc-file=string.c
@@ -1763,7 +1862,7 @@ class String
1763
1862
  def empty?: () -> bool
1764
1863
 
1765
1864
  # <!--
1766
- # rdoc-file=transcode.rdoc
1865
+ # rdoc-file=transcode.c
1767
1866
  # - encode(dst_encoding = Encoding.default_internal, **enc_opts) -> string
1768
1867
  # - encode(dst_encoding, src_encoding, **enc_opts) -> string
1769
1868
  # -->
@@ -1809,7 +1908,30 @@ class String
1809
1908
  # Optional keyword arguments `enc_opts` specify encoding options; see [Encoding
1810
1909
  # Options](rdoc-ref:encodings.rdoc@Encoding+Options).
1811
1910
  #
1812
- def encode: (?encoding encoding, ?encoding from_encoding, ?invalid: :replace ?, ?undef: :replace ?, ?replace: String, ?fallback: String::encode_fallback, ?xml: :text | :attr, ?universal_newline: true, ?cr_newline: true, ?crlf_newline: true) -> String
1911
+ # Please note that, unless `invalid: :replace` option is given, conversion from
1912
+ # an encoding `enc` to the same encoding `enc` (independent of whether `enc` is
1913
+ # given explicitly or implicitly) is a no-op, i.e. the string is simply copied
1914
+ # without any changes, and no exceptions are raised, even if there are invalid
1915
+ # bytes.
1916
+ #
1917
+ def encode: (
1918
+ ?encoding source_encoding,
1919
+ ?encoding? from_encoding,
1920
+ ?invalid: :replace ?,
1921
+ ?undef: :replace ?,
1922
+ ?replace: string?,
1923
+ ?xml: (:text | :attr)?,
1924
+ ?newline: (:universal | :crlf | :cr | :lf)?,
1925
+ ?universal_newline: boolish,
1926
+ ?cr_newline: boolish,
1927
+ ?crlf_newline: boolish,
1928
+ ?lf_newline: boolish,
1929
+ ?fallback: ^(String) -> string? | Method | _EncodeFallbackAref
1930
+ ) -> instance
1931
+
1932
+ interface _EncodeFallbackAref
1933
+ def []: (String) -> string?
1934
+ end
1813
1935
 
1814
1936
  # <!--
1815
1937
  # rdoc-file=transcode.c
@@ -1818,7 +1940,20 @@ class String
1818
1940
  # -->
1819
1941
  # Like #encode, but applies encoding changes to `self`; returns `self`.
1820
1942
  #
1821
- def encode!: (?encoding encoding, ?encoding from_encoding, ?invalid: :replace ?, ?undef: :replace ?, ?replace: String, ?fallback: String::encode_fallback, ?xml: :text | :attr, ?universal_newline: true, ?cr_newline: true, ?crlf_newline: true) -> self
1943
+ def encode!: (
1944
+ ?encoding source_encoding,
1945
+ ?encoding? from_encoding,
1946
+ ?invalid: :replace ?,
1947
+ ?undef: :replace ?,
1948
+ ?replace: string?,
1949
+ ?xml: (:text | :attr)?,
1950
+ ?newline: (:universal | :crlf | :cr | :lf)?,
1951
+ ?universal_newline: boolish,
1952
+ ?cr_newline: boolish,
1953
+ ?crlf_newline: boolish,
1954
+ ?lf_newline: boolish,
1955
+ ?fallback: ^(String) -> string? | Method | _EncodeFallbackAref
1956
+ ) -> self
1822
1957
 
1823
1958
  # <!--
1824
1959
  # rdoc-file=string.c
@@ -1888,7 +2023,7 @@ class String
1888
2023
  # s.force_encoding(Encoding::UTF_8) # => "łał"
1889
2024
  # s.valid_encoding? # => true
1890
2025
  #
1891
- def force_encoding: (string | Encoding encoding) -> self
2026
+ def force_encoding: (encoding enc) -> self
1892
2027
 
1893
2028
  # <!--
1894
2029
  # rdoc-file=string.c
@@ -1926,7 +2061,8 @@ class String
1926
2061
  # s.grapheme_clusters
1927
2062
  # # => ["ä", "-", "p", "q", "r", "-", "b̈", "-", "x", "y", "z", "-", "c̈"]
1928
2063
  #
1929
- def grapheme_clusters: () -> ::Array[::String]
2064
+ def grapheme_clusters: () -> Array[String]
2065
+ | () { (String grapheme_cluter) -> void } -> self
1930
2066
 
1931
2067
  # <!--
1932
2068
  # rdoc-file=string.c
@@ -1942,10 +2078,9 @@ class String
1942
2078
  #
1943
2079
  # Related: String#sub, String#sub!, String#gsub!.
1944
2080
  #
1945
- def gsub: (Regexp | string pattern, string replacement) -> String
1946
- | (Regexp | string pattern, Hash[String, String] hash) -> String
2081
+ def gsub: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> String
2082
+ | (Regexp | string pattern) -> Enumerator[String, String]
1947
2083
  | (Regexp | string pattern) { (String match) -> _ToS } -> String
1948
- | (Regexp | string pattern) -> ::Enumerator[String, self]
1949
2084
 
1950
2085
  # <!--
1951
2086
  # rdoc-file=string.c
@@ -1962,10 +2097,9 @@ class String
1962
2097
  #
1963
2098
  # Related: String#sub, String#gsub, String#sub!.
1964
2099
  #
1965
- def gsub!: (Regexp | string pattern, string replacement) -> String?
1966
- | (Regexp | string pattern, Hash[String, String] hash) -> String?
1967
- | (Regexp | string pattern) { (String match) -> _ToS } -> String?
1968
- | (Regexp | string pattern) -> ::Enumerator[String, self]
2100
+ def gsub!: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> self?
2101
+ | (Regexp | string pattern) -> Enumerator[String, self]
2102
+ | (Regexp | string pattern) { (String match) -> _ToS } -> self?
1969
2103
 
1970
2104
  # <!--
1971
2105
  # rdoc-file=string.c
@@ -2006,7 +2140,7 @@ class String
2006
2140
  # s.include?('fo') # => true
2007
2141
  # s.include?('food') # => false
2008
2142
  #
2009
- def include?: (string other_str) -> bool
2143
+ def include?: (string other_string) -> bool
2010
2144
 
2011
2145
  # <!--
2012
2146
  # rdoc-file=string.c
@@ -2052,7 +2186,7 @@ class String
2052
2186
  #
2053
2187
  # Related: String#rindex.
2054
2188
  #
2055
- def index: (Regexp | string substr_or_regexp, ?int offset) -> Integer?
2189
+ def index: (Regexp | string pattern, ?int offset) -> Integer?
2056
2190
 
2057
2191
  # <!--
2058
2192
  # rdoc-file=string.c
@@ -2069,7 +2203,7 @@ class String
2069
2203
  #
2070
2204
  # 'foo'.insert(-2, 'bar') # => "fobaro"
2071
2205
  #
2072
- def insert: (int index, string other_str) -> String
2206
+ def insert: (int index, string other_str) -> self
2073
2207
 
2074
2208
  # <!--
2075
2209
  # rdoc-file=string.c
@@ -2121,8 +2255,6 @@ class String
2121
2255
  # 'тест'.bytesize # => 8
2122
2256
  # 'こんにちは'.bytesize # => 15
2123
2257
  #
2124
- # String#size is an alias for String#length.
2125
- #
2126
2258
  def length: () -> Integer
2127
2259
 
2128
2260
  # <!--
@@ -2132,7 +2264,8 @@ class String
2132
2264
  # Forms substrings ("lines") of `self` according to the given arguments (see
2133
2265
  # String#each_line for details); returns the lines in an array.
2134
2266
  #
2135
- def lines: (?string separator, ?chomp: boolish) -> Array[String]
2267
+ def lines: (?string? separator, ?chomp: boolish) -> Array[String]
2268
+ | (?string? separator, ?chomp: boolish) { (String line) -> void } -> self
2136
2269
 
2137
2270
  # <!--
2138
2271
  # rdoc-file=string.c
@@ -2157,7 +2290,7 @@ class String
2157
2290
  #
2158
2291
  # Related: String#rjust, String#center.
2159
2292
  #
2160
- def ljust: (int integer, ?string padstr) -> String
2293
+ def ljust: (int size, ?string pad_string) -> String
2161
2294
 
2162
2295
  # <!--
2163
2296
  # rdoc-file=string.c
@@ -2193,7 +2326,7 @@ class String
2193
2326
  # -->
2194
2327
  # Returns a MatchData object (or `nil`) based on `self` and the given `pattern`.
2195
2328
  #
2196
- # Note: also updates Regexp@Special+global+variables.
2329
+ # Note: also updates Regexp@Global+Variables.
2197
2330
  #
2198
2331
  # * Computes `regexp` by converting `pattern` (if not already a Regexp).
2199
2332
  # regexp = Regexp.new(pattern)
@@ -2221,8 +2354,8 @@ class String
2221
2354
  # 'foo'.match(/x/) {|matchdata| matchdata } # => nil
2222
2355
  # 'foo'.match(/f/, 1) {|matchdata| matchdata } # => nil
2223
2356
  #
2224
- def match: (Regexp | string pattern, ?int pos) -> MatchData?
2225
- | [A] (Regexp | string pattern, ?int pos) { (MatchData) -> A } -> A
2357
+ def match: (Regexp | string pattern, ?int offset) -> MatchData?
2358
+ | [T] (Regexp | string pattern, ?int offset) { (MatchData matchdata) -> T } -> T?
2226
2359
 
2227
2360
  # <!--
2228
2361
  # rdoc-file=string.c
@@ -2231,7 +2364,7 @@ class String
2231
2364
  # Returns `true` or `false` based on whether a match is found for `self` and
2232
2365
  # `pattern`.
2233
2366
  #
2234
- # Note: does not update Regexp@Special+global+variables.
2367
+ # Note: does not update Regexp@Global+Variables.
2235
2368
  #
2236
2369
  # Computes `regexp` by converting `pattern` (if not already a Regexp).
2237
2370
  # regexp = Regexp.new(pattern)
@@ -2247,7 +2380,7 @@ class String
2247
2380
  # 'foo'.match?('f', 1) # => false
2248
2381
  # 'foo'.match?('o', 1) # => true
2249
2382
  #
2250
- def match?: (Regexp | string pattern, ?int pos) -> bool
2383
+ def match?: (Regexp | string pattern, ?int offset) -> bool
2251
2384
 
2252
2385
  # <!-- rdoc-file=string.c -->
2253
2386
  # Returns the successor to `self`. The successor is calculated by incrementing
@@ -2301,16 +2434,12 @@ class String
2301
2434
  #
2302
2435
  # ''.succ # => ""
2303
2436
  #
2304
- # String#next is an alias for String#succ.
2305
- #
2306
- def next: () -> String
2437
+ alias next succ
2307
2438
 
2308
2439
  # <!-- rdoc-file=string.c -->
2309
2440
  # Equivalent to String#succ, but modifies `self` in place; returns `self`.
2310
2441
  #
2311
- # String#next! is an alias for String#succ!.
2312
- #
2313
- def next!: () -> self
2442
+ alias next! succ!
2314
2443
 
2315
2444
  # <!--
2316
2445
  # rdoc-file=string.c
@@ -2373,7 +2502,7 @@ class String
2373
2502
  #
2374
2503
  # Related: String#rpartition, String#split.
2375
2504
  #
2376
- def partition: (Regexp | string sep_or_regexp) -> [ String, String, String ]
2505
+ def partition: (Regexp | string pattern) -> [String, String, String]
2377
2506
 
2378
2507
  # <!--
2379
2508
  # rdoc-file=string.c
@@ -2387,7 +2516,7 @@ class String
2387
2516
  #
2388
2517
  # Related: String#concat.
2389
2518
  #
2390
- def prepend: (*string other_strs) -> String
2519
+ def prepend: (*string other_strings) -> self
2391
2520
 
2392
2521
  # <!-- rdoc-file=string.c -->
2393
2522
  # Replaces the contents of `self` with the contents of `other_string`:
@@ -2395,7 +2524,7 @@ class String
2395
2524
  # s = 'foo' # => "foo"
2396
2525
  # s.replace('bar') # => "bar"
2397
2526
  #
2398
- def replace: (string other_str) -> String
2527
+ def replace: (string other_string) -> self
2399
2528
 
2400
2529
  # <!--
2401
2530
  # rdoc-file=string.c
@@ -2475,7 +2604,7 @@ class String
2475
2604
  #
2476
2605
  # Related: String#index.
2477
2606
  #
2478
- def rindex: (string | Regexp substr_or_regexp, ?int pos) -> Integer?
2607
+ def rindex: (Regexp | string pattern, ?int offset) -> Integer?
2479
2608
 
2480
2609
  # <!--
2481
2610
  # rdoc-file=string.c
@@ -2500,7 +2629,7 @@ class String
2500
2629
  #
2501
2630
  # Related: String#ljust, String#center.
2502
2631
  #
2503
- def rjust: (int integer, ?string padstr) -> String
2632
+ def rjust: (int size, ?string pad_string) -> String
2504
2633
 
2505
2634
  # <!--
2506
2635
  # rdoc-file=string.c
@@ -2532,7 +2661,7 @@ class String
2532
2661
  #
2533
2662
  # Related: String#partition, String#split.
2534
2663
  #
2535
- def rpartition: (string | Regexp sep_or_regexp) -> [ String, String, String ]
2664
+ def rpartition: (Regexp | string pattern) -> [String, String, String]
2536
2665
 
2537
2666
  # <!--
2538
2667
  # rdoc-file=string.c
@@ -2601,9 +2730,9 @@ class String
2601
2730
  # rceu lowlr
2602
2731
  #
2603
2732
  def scan: (Regexp pattern) -> Array[String | Array[String]]
2604
- | (Regexp pattern) { (String | Array[String]) -> void } -> self
2733
+ | (Regexp pattern) { (String | Array[String] matches) -> void } -> self
2605
2734
  | (string pattern) -> Array[String]
2606
- | (string pattern) { (String) -> void } -> self
2735
+ | (string pattern) { (String match) -> void } -> self
2607
2736
 
2608
2737
  # <!--
2609
2738
  # rdoc-file=string.c
@@ -2635,8 +2764,8 @@ class String
2635
2764
  # "\x81"
2636
2765
  # "\x81"
2637
2766
  #
2638
- def scrub: (?string repl) -> String
2639
- | () { (String bytes) -> string } -> String
2767
+ def scrub: (?string? replacement) -> String
2768
+ | (?nil) { (String bytes) -> string } -> String
2640
2769
 
2641
2770
  # <!--
2642
2771
  # rdoc-file=string.c
@@ -2646,8 +2775,8 @@ class String
2646
2775
  # -->
2647
2776
  # Like String#scrub, except that any replacements are made in `self`.
2648
2777
  #
2649
- def scrub!: (?string repl) -> self
2650
- | () { (String bytes) -> string } -> self
2778
+ def scrub!: (?string? replacement) -> self
2779
+ | (?nil) { (String bytes) -> string } -> self
2651
2780
 
2652
2781
  # <!--
2653
2782
  # rdoc-file=string.c
@@ -2661,7 +2790,7 @@ class String
2661
2790
  #
2662
2791
  # Related: String#getbyte.
2663
2792
  #
2664
- def setbyte: (int index, int integer) -> int
2793
+ def setbyte: [T < _ToInt] (int index, T byte) -> T
2665
2794
 
2666
2795
  # <!-- rdoc-file=string.c -->
2667
2796
  # Returns the count of characters (not bytes) in `self`:
@@ -2676,8 +2805,6 @@ class String
2676
2805
  # 'тест'.bytesize # => 8
2677
2806
  # 'こんにちは'.bytesize # => 15
2678
2807
  #
2679
- # String#size is an alias for String#length.
2680
- #
2681
2808
  alias size length
2682
2809
 
2683
2810
  # <!-- rdoc-file=string.c -->
@@ -2706,10 +2833,10 @@ class String
2706
2833
  # string.slice!("r") #=> "r"
2707
2834
  # string #=> "Thing"
2708
2835
  #
2709
- def slice!: (int integer, ?int integer) -> String?
2710
- | (Range[Integer] | Range[Integer?] range) -> String?
2711
- | (Regexp regexp, ?int | String capture) -> String?
2712
- | (String other_str) -> String?
2836
+ def slice!: (int index, ?int length) -> String?
2837
+ | (range[int?] range) -> String?
2838
+ | (String substring) -> String?
2839
+ | (Regexp regexp, ?MatchData::capture backref) -> String?
2713
2840
 
2714
2841
  # <!--
2715
2842
  # rdoc-file=string.c
@@ -2797,8 +2924,8 @@ class String
2797
2924
  #
2798
2925
  # Related: String#partition, String#rpartition.
2799
2926
  #
2800
- def split: (?Regexp | string pattern, ?int limit) -> Array[String]
2801
- | (?Regexp | string pattern, ?int limit) { (String) -> void } -> self
2927
+ def split: (?Regexp | string | nil pattern, ?int limit) -> Array[String]
2928
+ | (?Regexp | string | nil pattern, ?int limit) { (String substring) -> void } -> self
2802
2929
 
2803
2930
  # <!--
2804
2931
  # rdoc-file=string.c
@@ -2816,7 +2943,7 @@ class String
2816
2943
  # " now is the".squeeze(" ") #=> " now is the"
2817
2944
  # "putters shoot balls".squeeze("m-z") #=> "puters shot balls"
2818
2945
  #
2819
- def squeeze: (*string other_str) -> String
2946
+ def squeeze: (*selector selectors) -> String
2820
2947
 
2821
2948
  # <!--
2822
2949
  # rdoc-file=string.c
@@ -2825,7 +2952,7 @@ class String
2825
2952
  # Like String#squeeze, but modifies `self` in place. Returns `self` if any
2826
2953
  # changes were made, `nil` otherwise.
2827
2954
  #
2828
- def squeeze!: (*string other_str) -> self?
2955
+ def squeeze!: (*selector selectors) -> self?
2829
2956
 
2830
2957
  # <!--
2831
2958
  # rdoc-file=string.c
@@ -2851,7 +2978,7 @@ class String
2851
2978
  #
2852
2979
  # Related: String#end_with?.
2853
2980
  #
2854
- def start_with?: (*string prefixes) -> bool
2981
+ def start_with?: (*Regexp | string prefixes) -> bool
2855
2982
 
2856
2983
  # <!--
2857
2984
  # rdoc-file=string.c
@@ -2892,7 +3019,7 @@ class String
2892
3019
  #
2893
3020
  # Related: String#sub!, String#gsub, String#gsub!.
2894
3021
  #
2895
- def sub: (Regexp | string pattern, string | Hash[String, String] replacement) -> String
3022
+ def sub: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> String
2896
3023
  | (Regexp | string pattern) { (String match) -> _ToS } -> String
2897
3024
 
2898
3025
  # <!--
@@ -2907,8 +3034,8 @@ class String
2907
3034
  #
2908
3035
  # Related: String#sub, String#gsub, String#gsub!.
2909
3036
  #
2910
- def sub!: (Regexp | string pattern, string | Hash[String, String] replacement) -> self?
2911
- | (Regexp | string pattern) { (String match) -> _ToS } -> String?
3037
+ def sub!: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> self?
3038
+ | (Regexp | string pattern) { (String match) -> _ToS } -> self?
2912
3039
 
2913
3040
  # <!--
2914
3041
  # rdoc-file=string.c
@@ -2965,8 +3092,6 @@ class String
2965
3092
  #
2966
3093
  # ''.succ # => ""
2967
3094
  #
2968
- # String#next is an alias for String#succ.
2969
- #
2970
3095
  def succ: () -> String
2971
3096
 
2972
3097
  # <!--
@@ -2975,9 +3100,7 @@ class String
2975
3100
  # -->
2976
3101
  # Equivalent to String#succ, but modifies `self` in place; returns `self`.
2977
3102
  #
2978
- # String#next! is an alias for String#succ!.
2979
- #
2980
- def succ!: () -> String
3103
+ def succ!: () -> self
2981
3104
 
2982
3105
  # <!--
2983
3106
  # rdoc-file=string.c
@@ -2994,7 +3117,7 @@ class String
2994
3117
  #
2995
3118
  # This is not a particularly strong checksum.
2996
3119
  #
2997
- def sum: (?int n) -> Integer
3120
+ def sum: (?int bits) -> Integer
2998
3121
 
2999
3122
  # <!--
3000
3123
  # rdoc-file=string.c
@@ -3117,7 +3240,7 @@ class String
3117
3240
  # 'abcdef'.to_i # => 0
3118
3241
  # '2'.to_i(2) # => 0
3119
3242
  #
3120
- def to_i: (?int base) -> Integer
3243
+ def to_i: (?int radix) -> Integer
3121
3244
 
3122
3245
  # <!--
3123
3246
  # rdoc-file=rational.c
@@ -3155,17 +3278,13 @@ class String
3155
3278
  # Returns `self` if `self` is a String, or `self` converted to a String if
3156
3279
  # `self` is a subclass of String.
3157
3280
  #
3158
- # String#to_str is an alias for String#to_s.
3159
- #
3160
3281
  def to_s: () -> String
3161
3282
 
3162
3283
  # <!-- rdoc-file=string.c -->
3163
3284
  # Returns `self` if `self` is a String, or `self` converted to a String if
3164
3285
  # `self` is a subclass of String.
3165
3286
  #
3166
- # String#to_str is an alias for String#to_s.
3167
- #
3168
- def to_str: () -> String
3287
+ alias to_str to_s
3169
3288
 
3170
3289
  # <!-- rdoc-file=string.c -->
3171
3290
  # Returns the Symbol corresponding to *str*, creating the symbol if it did not
@@ -3182,7 +3301,7 @@ class String
3182
3301
  #
3183
3302
  # 'cat and dog'.to_sym #=> :"cat and dog"
3184
3303
  #
3185
- def to_sym: () -> Symbol
3304
+ alias to_sym intern
3186
3305
 
3187
3306
  # <!--
3188
3307
  # rdoc-file=string.c
@@ -3222,7 +3341,7 @@ class String
3222
3341
  # 'i-b-m'.tr('b\-z', 'a-z') # => "ibabm" # Escaped embedded hyphen.
3223
3342
  # 'foo\\bar'.tr('ab\\', 'XYZ') # => "fooZYXr" # Escaped backslash.
3224
3343
  #
3225
- def tr: (string from_str, string to_str) -> String
3344
+ def tr: (selector source, string relpacement) -> String
3226
3345
 
3227
3346
  # <!--
3228
3347
  # rdoc-file=string.c
@@ -3231,7 +3350,7 @@ class String
3231
3350
  # Like String#tr, but modifies `self` in place. Returns `self` if any changes
3232
3351
  # were made, `nil` otherwise.
3233
3352
  #
3234
- def tr!: (string from_str, string to_str) -> String?
3353
+ def tr!: (selector source, string relpacement) -> self?
3235
3354
 
3236
3355
  # <!--
3237
3356
  # rdoc-file=string.c
@@ -3246,7 +3365,7 @@ class String
3246
3365
  #
3247
3366
  # Related: String#squeeze.
3248
3367
  #
3249
- def tr_s: (string from_str, string to_str) -> String
3368
+ def tr_s: (selector source, string replacement) -> String
3250
3369
 
3251
3370
  # <!--
3252
3371
  # rdoc-file=string.c
@@ -3257,7 +3376,7 @@ class String
3257
3376
  #
3258
3377
  # Related: String#squeeze!.
3259
3378
  #
3260
- def tr_s!: (string from_str, string to_str) -> String?
3379
+ def tr_s!: (selector source, string replacement) -> self?
3261
3380
 
3262
3381
  # <!--
3263
3382
  # rdoc-file=string.c
@@ -3309,7 +3428,7 @@ class String
3309
3428
  #
3310
3429
  # Related: String#unicode_normalize!, String#unicode_normalized?.
3311
3430
  #
3312
- def unicode_normalize: (?:nfc | :nfd | :nfkc | :nfkd) -> String
3431
+ def unicode_normalize: (?:nfc | :nfd | :nfkc | :nfkd form) -> self
3313
3432
 
3314
3433
  # <!--
3315
3434
  # rdoc-file=string.c
@@ -3320,7 +3439,7 @@ class String
3320
3439
  #
3321
3440
  # Related String#unicode_normalized?.
3322
3441
  #
3323
- def unicode_normalize!: (?:nfc | :nfd | :nfkc | :nfkd) -> String
3442
+ def unicode_normalize!: (?:nfc | :nfd | :nfkc | :nfkd form) -> self
3324
3443
 
3325
3444
  # <!--
3326
3445
  # rdoc-file=string.c
@@ -3353,7 +3472,8 @@ class String
3353
3472
  # Extracts data from `self`, forming objects that become the elements of a new
3354
3473
  # array; returns that array. See [Packed Data](rdoc-ref:packed_data.rdoc).
3355
3474
  #
3356
- def unpack: (String format, ?offset: Integer) -> Array[Integer | Float | String | nil]
3475
+ def unpack: (string template, ?offset: int) -> Array[Integer | Float | String | nil]
3476
+ | (string template, ?offset: int) { (Integer | Float | String | nil value) -> void } -> nil
3357
3477
 
3358
3478
  # <!--
3359
3479
  # rdoc-file=pack.rb
@@ -3362,7 +3482,7 @@ class String
3362
3482
  # Like String#unpack, but unpacks and returns only the first extracted object.
3363
3483
  # See [Packed Data](rdoc-ref:packed_data.rdoc).
3364
3484
  #
3365
- def unpack1: (String format) -> (Integer | Float | String | nil)
3485
+ def unpack1: (string template, ?offset: int) -> (Integer | Float | String)?
3366
3486
 
3367
3487
  # <!--
3368
3488
  # rdoc-file=string.c
@@ -3439,8 +3559,8 @@ class String
3439
3559
  #
3440
3560
  # 'a8'.upto('b6') # => #<Enumerator: "a8":upto("b6")>
3441
3561
  #
3442
- def upto: (string other_str, ?boolish exclusive) -> Enumerator[String, self]
3443
- | (string other_str, ?boolish exclusive) { (String s) -> void } -> self
3562
+ def upto: (string other_string, ?boolish exclusive) -> Enumerator[String, self]
3563
+ | (string other_string, ?boolish exclusive) { (String s) -> void } -> self
3444
3564
 
3445
3565
  # <!--
3446
3566
  # rdoc-file=string.c
@@ -3453,79 +3573,12 @@ class String
3453
3573
  # "\x80".force_encoding("UTF-8").valid_encoding? # => false
3454
3574
  #
3455
3575
  def valid_encoding?: () -> bool
3456
-
3457
- private
3458
-
3459
- # <!--
3460
- # rdoc-file=string.c
3461
- # - String.new(string = '', **opts) -> new_string
3462
- # -->
3463
- # Returns a new String that is a copy of `string`.
3464
- #
3465
- # With no arguments, returns the empty string with the Encoding `ASCII-8BIT`:
3466
- #
3467
- # s = String.new
3468
- # s # => ""
3469
- # s.encoding # => #<Encoding:ASCII-8BIT>
3470
- #
3471
- # With optional argument `string` and no keyword arguments, returns a copy of
3472
- # `string` with the same encoding:
3473
- #
3474
- # String.new('foo') # => "foo"
3475
- # String.new('тест') # => "тест"
3476
- # String.new('こんにちは') # => "こんにちは"
3477
- #
3478
- # (Unlike String.new, a [string
3479
- # literal](rdoc-ref:syntax/literals.rdoc@String+Literals) like `''` or a [here
3480
- # document literal](rdoc-ref:syntax/literals.rdoc@Here+Document+Literals) always
3481
- # has [script encoding](rdoc-ref:encodings.rdoc@Script+Encoding).)
3482
- #
3483
- # With optional keyword argument `encoding`, returns a copy of `string` with the
3484
- # specified encoding; the `encoding` may be an Encoding object, an encoding
3485
- # name, or an encoding name alias:
3486
- #
3487
- # String.new('foo', encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII>
3488
- # String.new('foo', encoding: 'US-ASCII').encoding # => #<Encoding:US-ASCII>
3489
- # String.new('foo', encoding: 'ASCII').encoding # => #<Encoding:US-ASCII>
3490
- #
3491
- # The given encoding need not be valid for the string's content, and that
3492
- # validity is not checked:
3493
- #
3494
- # s = String.new('こんにちは', encoding: 'ascii')
3495
- # s.valid_encoding? # => false
3496
- #
3497
- # But the given `encoding` itself is checked:
3498
- #
3499
- # String.new('foo', encoding: 'bar') # Raises ArgumentError.
3500
- #
3501
- # With optional keyword argument `capacity`, returns a copy of `string` (or an
3502
- # empty string, if `string` is not given); the given `capacity` is advisory
3503
- # only, and may or may not set the size of the internal buffer, which may in
3504
- # turn affect performance:
3505
- #
3506
- # String.new(capacity: 1)
3507
- # String.new('foo', capacity: 4096)
3508
- #
3509
- # The `string`, `encoding`, and `capacity` arguments may all be used together:
3510
- #
3511
- # String.new('hello', encoding: 'UTF-8', capacity: 25)
3512
- #
3513
- def initialize: (?string str, ?encoding: encoding, ?capacity: int) -> void
3514
-
3515
- # <!--
3516
- # rdoc-file=string.c
3517
- # - replace(other_string) -> self
3518
- # -->
3519
- # Replaces the contents of `self` with the contents of `other_string`:
3520
- #
3521
- # s = 'foo' # => "foo"
3522
- # s.replace('bar') # => "bar"
3523
- #
3524
- alias initialize_copy replace
3525
3576
  end
3526
3577
 
3578
+ %a{steep:deprecated}
3527
3579
  interface _ArefFromStringToString
3528
3580
  def []: (String) -> String
3529
3581
  end
3530
3582
 
3583
+ %a{steep:deprecated}
3531
3584
  type String::encode_fallback = Hash[String, String] | Proc | Method | _ArefFromStringToString