rbs 3.10.0.pre.2 → 3.10.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/c-check.yml +1 -1
  3. data/.github/workflows/comments.yml +2 -2
  4. data/.github/workflows/ruby.yml +7 -7
  5. data/CHANGELOG.md +49 -0
  6. data/core/array.rbs +56 -3
  7. data/core/complex.rbs +32 -21
  8. data/core/encoding.rbs +3 -7
  9. data/core/enumerable.rbs +1 -1
  10. data/core/enumerator.rbs +18 -1
  11. data/core/fiber.rbs +2 -1
  12. data/core/file.rbs +1 -1
  13. data/core/file_test.rbs +1 -1
  14. data/core/float.rbs +208 -21
  15. data/core/gc.rbs +4 -9
  16. data/core/hash.rbs +4 -4
  17. data/core/integer.rbs +78 -38
  18. data/core/io/buffer.rbs +18 -7
  19. data/core/io.rbs +8 -8
  20. data/core/kernel.rbs +8 -8
  21. data/core/module.rbs +17 -6
  22. data/core/numeric.rbs +8 -8
  23. data/core/object_space.rbs +13 -20
  24. data/core/pathname.rbs +2 -3
  25. data/core/ractor.rbs +4 -4
  26. data/core/range.rbs +1 -1
  27. data/core/rational.rbs +37 -24
  28. data/core/rbs/unnamed/argf.rbs +1 -1
  29. data/core/regexp.rbs +3 -3
  30. data/core/ruby.rbs +53 -0
  31. data/core/rubygems/version.rbs +2 -3
  32. data/core/set.rbs +86 -64
  33. data/core/string.rbs +275 -141
  34. data/core/thread.rbs +9 -9
  35. data/core/trace_point.rbs +7 -4
  36. data/lib/rbs/test/type_check.rb +1 -0
  37. data/lib/rbs/version.rb +1 -1
  38. data/lib/rdoc/discover.rb +1 -1
  39. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  40. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  41. data/stdlib/date/0/date.rbs +67 -59
  42. data/stdlib/date/0/date_time.rbs +1 -1
  43. data/stdlib/json/0/json.rbs +1 -0
  44. data/stdlib/objspace/0/objspace.rbs +1 -1
  45. data/stdlib/openssl/0/openssl.rbs +150 -80
  46. data/stdlib/psych/0/psych.rbs +3 -3
  47. data/stdlib/stringio/0/stringio.rbs +796 -37
  48. data/stdlib/strscan/0/string_scanner.rbs +1 -1
  49. data/stdlib/tempfile/0/tempfile.rbs +2 -2
  50. data/stdlib/time/0/time.rbs +1 -1
  51. data/stdlib/timeout/0/timeout.rbs +63 -7
  52. data/stdlib/uri/0/generic.rbs +1 -1
  53. metadata +3 -2
data/core/string.rbs CHANGED
@@ -187,10 +187,10 @@
187
187
  #
188
188
  # *Counts*
189
189
  #
190
- # * #length (aliased as #size): Returns the count of characters (not bytes).
191
- # * #empty?: Returns whether the length of `self` is zero.
192
190
  # * #bytesize: Returns the count of bytes.
193
191
  # * #count: Returns the count of substrings matching given strings.
192
+ # * #empty?: Returns whether the length of `self` is zero.
193
+ # * #length (aliased as #size): Returns the count of characters (not bytes).
194
194
  #
195
195
  # *Substrings*
196
196
  #
@@ -350,8 +350,8 @@
350
350
  # *Substitution*
351
351
  #
352
352
  # * #dump: Returns a printable version of `self`, enclosed in double-quotes.
353
- # * #undump: Returns a copy of `self` with all `\xNN` notations replaced by
354
- # `\uNNNN` notations and all escaped characters unescaped.
353
+ # * #undump: Inverse of #dump; returns a copy of `self` with changes of the
354
+ # kinds made by #dump "undone."
355
355
  # * #sub: Returns a copy of `self` with the first substring matching a given
356
356
  # pattern replaced with a given replacement string.
357
357
  # * #gsub: Returns a copy of `self` with each substring that matches a given
@@ -660,10 +660,10 @@
660
660
  #
661
661
  # *Counts*
662
662
  #
663
- # * #length (aliased as #size): Returns the count of characters (not bytes).
664
- # * #empty?: Returns whether the length of `self` is zero.
665
663
  # * #bytesize: Returns the count of bytes.
666
664
  # * #count: Returns the count of substrings matching given strings.
665
+ # * #empty?: Returns whether the length of `self` is zero.
666
+ # * #length (aliased as #size): Returns the count of characters (not bytes).
667
667
  #
668
668
  # *Substrings*
669
669
  #
@@ -823,8 +823,8 @@
823
823
  # *Substitution*
824
824
  #
825
825
  # * #dump: Returns a printable version of `self`, enclosed in double-quotes.
826
- # * #undump: Returns a copy of `self` with all `\xNN` notations replaced by
827
- # `\uNNNN` notations and all escaped characters unescaped.
826
+ # * #undump: Inverse of #dump; returns a copy of `self` with changes of the
827
+ # kinds made by #dump "undone."
828
828
  # * #sub: Returns a copy of `self` with the first substring matching a given
829
829
  # pattern replaced with a given replacement string.
830
830
  # * #gsub: Returns a copy of `self` with each substring that matches a given
@@ -1042,7 +1042,7 @@ class String
1042
1042
  # -->
1043
1043
  # Returns the result of formatting `object` into the format specifications
1044
1044
  # contained in `self` (see [Format
1045
- # Specifications](rdoc-ref:format_specifications.rdoc)):
1045
+ # Specifications](rdoc-ref:language/format_specifications.rdoc)):
1046
1046
  #
1047
1047
  # '%05d' % 123 # => "00123"
1048
1048
  #
@@ -1306,7 +1306,7 @@ class String
1306
1306
  # 'hello'[0] # => "h"
1307
1307
  # 'hello'[4] # => "o"
1308
1308
  # 'hello'[5] # => nil
1309
- # 'тест'[2] # => "с"
1309
+ # 'Привет'[2] # => "и"
1310
1310
  # 'こんにちは'[4] # => "は"
1311
1311
  #
1312
1312
  # With negative integer argument `index` given, counts backward from the end of
@@ -1387,7 +1387,7 @@ class String
1387
1387
  # 'hello'['ell'] # => "ell"
1388
1388
  # 'hello'[''] # => ""
1389
1389
  # 'hello'['nosuch'] # => nil
1390
- # 'тест'['ес'] # => "ес"
1390
+ # 'Привет'['ив'] # => "ив"
1391
1391
  # 'こんにちは'['んにち'] # => "んにち"
1392
1392
  #
1393
1393
  # Related: see [Converting to New
@@ -1449,7 +1449,7 @@ class String
1449
1449
  # size `length` characters (as available) beginning at character offset
1450
1450
  # specified by `start`.
1451
1451
  #
1452
- # If argument `start` is non-negative, the offset is +start':
1452
+ # If argument `start` is non-negative, the offset is `start`:
1453
1453
  #
1454
1454
  # s = 'hello'
1455
1455
  # s[0, 1] = 'foo' # => "foo"
@@ -1989,23 +1989,30 @@ class String
1989
1989
 
1990
1990
  # <!--
1991
1991
  # rdoc-file=string.c
1992
- # - capitalize(mapping = :ascii) -> string
1992
+ # - capitalize(mapping = :ascii) -> new_string
1993
1993
  # -->
1994
1994
  # Returns a string containing the characters in `self`, each with possibly
1995
1995
  # changed case:
1996
1996
  #
1997
- # * The first character is upcased.
1998
- # * All other characters are downcased.
1997
+ # * The first character made uppercase.
1998
+ # * All other characters are made lowercase.
1999
1999
  #
2000
2000
  # Examples:
2001
2001
  #
2002
- # 'hello world'.capitalize # => "Hello world"
2003
- # 'HELLO WORLD'.capitalize # => "Hello world"
2002
+ # 'hello'.capitalize # => "Hello"
2003
+ # 'HELLO'.capitalize # => "Hello"
2004
+ # 'straße'.capitalize # => "Straße" # Lowercase 'ß' not changed.
2005
+ # 'STRAẞE'.capitalize # => "Straße" # Uppercase 'ẞ' downcased to 'ß'.
2006
+ # 'привет'.capitalize # => "Привет"
2007
+ # 'ПРИВЕТ'.capitalize # => "Привет"
2004
2008
  #
2005
- # Some characters do not have upcase and downcase, and so are not changed; see
2006
- # [Case Mapping](rdoc-ref:case_mapping.rdoc):
2009
+ # Some characters (and some character sets) do not have upcase and downcase
2010
+ # versions; see [Case Mapping](rdoc-ref:case_mapping.rdoc):
2007
2011
  #
2008
- # '1, 2, 3, ...'.capitalize # => "1, 2, 3, ..."
2012
+ # s = '1, 2, 3, ...'
2013
+ # s.capitalize == s # => true
2014
+ # s = 'こんにちは'
2015
+ # s.capitalize == s # => true
2009
2016
  #
2010
2017
  # The casing is affected by the given `mapping`, which may be `:ascii`, `:fold`,
2011
2018
  # or `:turkic`; see [Case Mappings](rdoc-ref:case_mapping.rdoc@Case+Mappings).
@@ -2631,18 +2638,25 @@ class String
2631
2638
 
2632
2639
  # <!--
2633
2640
  # rdoc-file=string.c
2634
- # - downcase(mapping) -> string
2641
+ # - downcase(mapping = :ascii) -> new_string
2635
2642
  # -->
2636
2643
  # Returns a new string containing the downcased characters in `self`:
2637
2644
  #
2638
- # 'Hello, World!'.downcase # => "hello, world!"
2639
- # 'ТЕСТ'.downcase # => "тест"
2640
- # 'よろしくお願いします'.downcase # => "よろしくお願いします"
2645
+ # 'HELLO'.downcase # => "hello"
2646
+ # 'STRAẞE'.downcase # => "straße"
2647
+ # 'ПРИВЕТ'.downcase # => "привет"
2648
+ # 'RubyGems.org'.downcase # => "rubygems.org"
2649
+ #
2650
+ # Some characters (and some character sets) do not have upcase and downcase
2651
+ # versions; see [Case Mapping](rdoc-ref:case_mapping.rdoc):
2641
2652
  #
2642
- # Some characters do not have upcased and downcased versions.
2653
+ # s = '1, 2, 3, ...'
2654
+ # s.downcase == s # => true
2655
+ # s = 'こんにちは'
2656
+ # s.downcase == s # => true
2643
2657
  #
2644
- # The casing may be affected by the given `mapping`; see [Case
2645
- # Mapping](rdoc-ref:case_mapping.rdoc).
2658
+ # The casing is affected by the given `mapping`, which may be `:ascii`, `:fold`,
2659
+ # or `:turkic`; see [Case Mappings](rdoc-ref:case_mapping.rdoc@Case+Mappings).
2646
2660
  #
2647
2661
  # Related: see [Converting to New
2648
2662
  # String](rdoc-ref:String@Converting+to+New+String).
@@ -2672,60 +2686,104 @@ class String
2672
2686
  # rdoc-file=string.c
2673
2687
  # - dump -> new_string
2674
2688
  # -->
2675
- # Returns a printable version of `self`, enclosed in double-quotes:
2689
+ # For an ordinary string, this method, +String#dump+, returns a printable
2690
+ # ASCII-only version of `self`, enclosed in double-quotes.
2691
+ #
2692
+ # For a dumped string, method String#undump is the inverse of +String#dump+; it
2693
+ # returns a "restored" version of `self`, where all the dumping changes have
2694
+ # been undone.
2695
+ #
2696
+ # In the simplest case, the dumped string contains the original string, enclosed
2697
+ # in double-quotes; this example is done in `irb` (interactive Ruby), which uses
2698
+ # method `inspect` to render the results:
2699
+ #
2700
+ # s = 'hello' # => "hello"
2701
+ # s.dump # => "\"hello\""
2702
+ # s.dump.undump # => "hello"
2703
+ #
2704
+ # Keep in mind that in the second line above:
2705
+ #
2706
+ # * The outer double-quotes are put on by `inspect`, and *are* *not* part of
2707
+ # the output of #dump.
2708
+ # * The inner double-quotes *are* part of the output of `dump`, and are
2709
+ # escaped by `inspect` because they are within the outer double-quotes.
2710
+ #
2711
+ # To avoid confusion, we'll use this helper method to omit the outer
2712
+ # double-quotes:
2713
+ #
2714
+ # def dump(s)
2715
+ # print "String: ", s, "\n"
2716
+ # print "Dumped: ", s.dump, "\n"
2717
+ # print "Undumped: ", s.dump.undump, "\n"
2718
+ # end
2676
2719
  #
2677
- # 'hello'.dump # => "\"hello\""
2720
+ # So that for string `'hello'`, we'll see:
2678
2721
  #
2679
- # Certain special characters are rendered with escapes:
2722
+ # String: hello
2723
+ # Dumped: "hello"
2724
+ # Undumped: hello
2680
2725
  #
2681
- # '"'.dump # => "\"\\\"\""
2682
- # '\\'.dump # => "\"\\\\\""
2726
+ # In a dump, certain special characters are escaped:
2683
2727
  #
2684
- # Non-printing characters are rendered with escapes:
2728
+ # String: "
2729
+ # Dumped: "\""
2730
+ # Undumped: "
2731
+ #
2732
+ # String: \
2733
+ # Dumped: "\\"
2734
+ # Undumped: \
2735
+ #
2736
+ # In a dump, unprintable characters are replaced by printable ones; the
2737
+ # unprintable characters are the whitespace characters (other than space
2738
+ # itself); here we see the ordinals for those characers, together with
2739
+ # explanatory text:
2740
+ #
2741
+ # h = {
2742
+ # 7 => 'Alert (BEL)',
2743
+ # 8 => 'Backspace (BS)',
2744
+ # 9 => 'Horizontal tab (HT)',
2745
+ # 10 => 'Linefeed (LF)',
2746
+ # 11 => 'Vertical tab (VT)',
2747
+ # 12 => 'Formfeed (FF)',
2748
+ # 13 => 'Carriage return (CR)'
2749
+ # }
2750
+ #
2751
+ # In this example, the dumped output is printed by method #inspect, and so
2752
+ # contains both outer double-quotes and escaped inner double-quotes:
2685
2753
  #
2686
2754
  # s = ''
2687
- # s << 7 # Alarm (bell).
2688
- # s << 8 # Back space.
2689
- # s << 9 # Horizontal tab.
2690
- # s << 10 # Line feed.
2691
- # s << 11 # Vertical tab.
2692
- # s << 12 # Form feed.
2693
- # s << 13 # Carriage return.
2694
- # s # => "\a\b\t\n\v\f\r"
2695
- # s.dump # => "\"\\a\\b\\t\\n\\v\\f\\r\""
2696
- #
2697
- # If `self` is encoded in UTF-8 and contains Unicode characters, renders Unicode
2698
- # characters in Unicode escape sequence:
2699
- #
2700
- # 'тест'.dump # => "\"\\u0442\\u0435\\u0441\\u0442\""
2701
- # 'こんにちは'.dump # => "\"\\u3053\\u3093\\u306B\\u3061\\u306F\""
2702
- #
2703
- # If the encoding of `self` is not ASCII-compatible (i.e.,
2704
- # `self.encoding.ascii_compatible?` returns `false`), renders all
2705
- # ASCII-compatible bytes as ASCII characters and all other bytes as hexadecimal.
2706
- # Appends `.dup.force_encoding(\"encoding\")`, where `<encoding>` is
2707
- # `self.encoding.name`:
2755
+ # h.keys.each {|i| s << i } # => [7, 8, 9, 10, 11, 12, 13]
2756
+ # s # => "\a\b\t\n\v\f\r"
2757
+ # s.dump # => "\"\\a\\b\\t\\n\\v\\f\\r\""
2708
2758
  #
2709
- # s = 'hello'
2710
- # s.encoding # => #<Encoding:UTF-8>
2711
- # s.dump # => "\"hello\""
2712
- # s.encode('utf-16').dump # => "\"\\xFE\\xFF\\x00h\\x00e\\x00l\\x00l\\x00o\".dup.force_encoding(\"UTF-16\")"
2713
- # s.encode('utf-16le').dump # => "\"h\\x00e\\x00l\\x00l\\x00o\\x00\".dup.force_encoding(\"UTF-16LE\")"
2759
+ # If `self` is encoded in UTF-8 and contains Unicode characters, each Unicode
2760
+ # character is dumped as a Unicode escape sequence:
2714
2761
  #
2715
- # s = 'тест'
2716
- # s.encoding # => #<Encoding:UTF-8>
2717
- # s.dump # => "\"\\u0442\\u0435\\u0441\\u0442\""
2718
- # s.encode('utf-16').dump # => "\"\\xFE\\xFF\\x04B\\x045\\x04A\\x04B\".dup.force_encoding(\"UTF-16\")"
2719
- # s.encode('utf-16le').dump # => "\"B\\x045\\x04A\\x04B\\x04\".dup.force_encoding(\"UTF-16LE\")"
2762
+ # String: тест
2763
+ # Dumped: "\u0442\u0435\u0441\u0442"
2764
+ # Undumped: тест
2720
2765
  #
2721
- # s = 'こんにちは'
2722
- # s.encoding # => #<Encoding:UTF-8>
2723
- # s.dump # => "\"\\u3053\\u3093\\u306B\\u3061\\u306F\""
2724
- # s.encode('utf-16').dump # => "\"\\xFE\\xFF0S0\\x930k0a0o\".dup.force_encoding(\"UTF-16\")"
2725
- # s.encode('utf-16le').dump # => "\"S0\\x930k0a0o0\".dup.force_encoding(\"UTF-16LE\")"
2766
+ # String: こんにちは
2767
+ # Dumped: "\u3053\u3093\u306B\u3061\u306F"
2768
+ # Undumped: こんにちは
2726
2769
  #
2727
- # Related: see [Converting to New
2728
- # String](rdoc-ref:String@Converting+to+New+String).
2770
+ # If the encoding of `self` is not ASCII-compatible (i.e., if
2771
+ # `self.encoding.ascii_compatible?` returns `false`), each ASCII-compatible byte
2772
+ # is dumped as an ASCII character, and all other bytes are dumped as
2773
+ # hexadecimal; also appends `.dup.force_encoding(\"encoding\")`, where
2774
+ # `<encoding>` is `self.encoding.name`:
2775
+ #
2776
+ # String: hello
2777
+ # Dumped: "\xFE\xFF\x00h\x00e\x00l\x00l\x00o".dup.force_encoding("UTF-16")
2778
+ # Undumped: hello
2779
+ #
2780
+ # String: тест
2781
+ # Dumped: "\xFE\xFF\x04B\x045\x04A\x04B".dup.force_encoding("UTF-16")
2782
+ # Undumped: тест
2783
+ #
2784
+ # String: こんにちは
2785
+ # Dumped: "\xFE\xFF0S0\x930k0a0o".dup.force_encoding("UTF-16")
2786
+ # Undumped: こんにちは
2729
2787
  #
2730
2788
  def dump: () -> String
2731
2789
 
@@ -3579,7 +3637,7 @@ class String
3579
3637
 
3580
3638
  # <!--
3581
3639
  # rdoc-file=string.c
3582
- # - lstrip -> new_string
3640
+ # - lstrip(*selectors) -> new_string
3583
3641
  # -->
3584
3642
  # Returns a copy of `self` with leading whitespace removed; see [Whitespace in
3585
3643
  # Strings](rdoc-ref:String@Whitespace+in+Strings):
@@ -3590,6 +3648,19 @@ class String
3590
3648
  # s.lstrip
3591
3649
  # # => "abc\u0000\t\n\v\f\r "
3592
3650
  #
3651
+ # If `selectors` are given, removes characters of `selectors` from the beginning
3652
+ # of `self`:
3653
+ #
3654
+ # s = "---abc+++"
3655
+ # s.lstrip("-") # => "abc+++"
3656
+ #
3657
+ # `selectors` must be valid character selectors (see [Character
3658
+ # Selectors](rdoc-ref:character_selectors.rdoc)), and may use any of its valid
3659
+ # forms, including negation, ranges, and escapes:
3660
+ #
3661
+ # "01234abc56789".lstrip("0-9") # "abc56789"
3662
+ # "01234abc56789".lstrip("0-9", "^4-6") # "4abc56789"
3663
+ #
3593
3664
  # Related: see [Converting to New
3594
3665
  # String](rdoc-ref:String@Converting+to+New+String).
3595
3666
  #
@@ -3597,7 +3668,7 @@ class String
3597
3668
 
3598
3669
  # <!--
3599
3670
  # rdoc-file=string.c
3600
- # - lstrip! -> self or nil
3671
+ # - lstrip!(*selectors) -> self or nil
3601
3672
  # -->
3602
3673
  # Like String#lstrip, except that:
3603
3674
  #
@@ -3857,7 +3928,7 @@ class String
3857
3928
  #
3858
3929
  # If `pattern` is a Regexp, performs the equivalent of `self.match(pattern)`
3859
3930
  # (also setting [pattern-matching global
3860
- # variables](rdoc-ref:globals.md@Pattern+Matching)):
3931
+ # variables](rdoc-ref:language/globals.md@Pattern+Matching)):
3861
3932
  #
3862
3933
  # 'hello'.partition(/h/) # => ["", "h", "ello"]
3863
3934
  # 'hello'.partition(/l/) # => ["he", "l", "lo"]
@@ -3871,7 +3942,7 @@ class String
3871
3942
  # If `pattern` is not a Regexp, converts it to a string (if it is not already
3872
3943
  # one), then performs the equivalent of `self.index(pattern)` (and does *not*
3873
3944
  # set [pattern-matching global
3874
- # variables](rdoc-ref:globals.md@Pattern+Matching)):
3945
+ # variables](rdoc-ref:language/globals.md@Pattern+Matching)):
3875
3946
  #
3876
3947
  # 'hello'.partition('h') # => ["", "h", "ello"]
3877
3948
  # 'hello'.partition('l') # => ["he", "l", "lo"]
@@ -4062,7 +4133,7 @@ class String
4062
4133
  #
4063
4134
  # If `pattern` is a Regexp, searches for the last matching substring (also
4064
4135
  # setting [pattern-matching global
4065
- # variables](rdoc-ref:globals.md@Pattern+Matching)):
4136
+ # variables](rdoc-ref:language/globals.md@Pattern+Matching)):
4066
4137
  #
4067
4138
  # 'hello'.rpartition(/l/) # => ["hel", "l", "o"]
4068
4139
  # 'hello'.rpartition(/ll/) # => ["he", "ll", "o"]
@@ -4075,7 +4146,8 @@ class String
4075
4146
  #
4076
4147
  # If `pattern` is not a Regexp, converts it to a string (if it is not already
4077
4148
  # one), then searches for the last matching substring (and does *not* set
4078
- # [pattern-matching global variables](rdoc-ref:globals.md@Pattern+Matching)):
4149
+ # [pattern-matching global
4150
+ # variables](rdoc-ref:language/globals.md@Pattern+Matching)):
4079
4151
  #
4080
4152
  # 'hello'.rpartition('l') # => ["hel", "l", "o"]
4081
4153
  # 'hello'.rpartition('ll') # => ["he", "ll", "o"]
@@ -4092,7 +4164,7 @@ class String
4092
4164
 
4093
4165
  # <!--
4094
4166
  # rdoc-file=string.c
4095
- # - rstrip -> new_string
4167
+ # - rstrip(*selectors) -> new_string
4096
4168
  # -->
4097
4169
  # Returns a copy of `self` with trailing whitespace removed; see [Whitespace in
4098
4170
  # Strings](rdoc-ref:String@Whitespace+in+Strings):
@@ -4102,6 +4174,19 @@ class String
4102
4174
  # s # => "\u0000\t\n\v\f\r abc\u0000\t\n\v\f\r "
4103
4175
  # s.rstrip # => "\u0000\t\n\v\f\r abc"
4104
4176
  #
4177
+ # If `selectors` are given, removes characters of `selectors` from the end of
4178
+ # `self`:
4179
+ #
4180
+ # s = "---abc+++"
4181
+ # s.rstrip("+") # => "---abc"
4182
+ #
4183
+ # `selectors` must be valid character selectors (see [Character
4184
+ # Selectors](rdoc-ref:character_selectors.rdoc)), and may use any of its valid
4185
+ # forms, including negation, ranges, and escapes:
4186
+ #
4187
+ # "01234abc56789".rstrip("0-9") # "01234abc"
4188
+ # "01234abc56789".rstrip("0-9", "^4-6") # "01234abc56"
4189
+ #
4105
4190
  # Related: see [Converting to New
4106
4191
  # String](rdoc-ref:String@Converting+to+New+String).
4107
4192
  #
@@ -4109,7 +4194,7 @@ class String
4109
4194
 
4110
4195
  # <!--
4111
4196
  # rdoc-file=string.c
4112
- # - rstrip! -> self or nil
4197
+ # - rstrip!(*selectors) -> self or nil
4113
4198
  # -->
4114
4199
  # Like String#rstrip, except that:
4115
4200
  #
@@ -4258,7 +4343,7 @@ class String
4258
4343
  # 'hello'[0] # => "h"
4259
4344
  # 'hello'[4] # => "o"
4260
4345
  # 'hello'[5] # => nil
4261
- # 'тест'[2] # => "с"
4346
+ # 'Привет'[2] # => "и"
4262
4347
  # 'こんにちは'[4] # => "は"
4263
4348
  #
4264
4349
  # With negative integer argument `index` given, counts backward from the end of
@@ -4339,7 +4424,7 @@ class String
4339
4424
  # 'hello'['ell'] # => "ell"
4340
4425
  # 'hello'[''] # => ""
4341
4426
  # 'hello'['nosuch'] # => nil
4342
- # 'тест'['ес'] # => "ес"
4427
+ # 'Привет'['ив'] # => "ив"
4343
4428
  # 'こんにちは'['んにち'] # => "んにち"
4344
4429
  #
4345
4430
  # Related: see [Converting to New
@@ -4564,7 +4649,7 @@ class String
4564
4649
 
4565
4650
  # <!--
4566
4651
  # rdoc-file=string.c
4567
- # - strip -> new_string
4652
+ # - strip(*selectors) -> new_string
4568
4653
  # -->
4569
4654
  # Returns a copy of `self` with leading and trailing whitespace removed; see
4570
4655
  # [Whitespace in Strings](rdoc-ref:String@Whitespace+in+Strings):
@@ -4574,6 +4659,20 @@ class String
4574
4659
  # # => "\u0000\t\n\v\f\r abc\u0000\t\n\v\f\r "
4575
4660
  # s.strip # => "abc"
4576
4661
  #
4662
+ # If `selectors` are given, removes characters of `selectors` from both ends of
4663
+ # `self`:
4664
+ #
4665
+ # s = "---abc+++"
4666
+ # s.strip("-+") # => "abc"
4667
+ # s.strip("+-") # => "abc"
4668
+ #
4669
+ # `selectors` must be valid character selectors (see [Character
4670
+ # Selectors](rdoc-ref:character_selectors.rdoc)), and may use any of its valid
4671
+ # forms, including negation, ranges, and escapes:
4672
+ #
4673
+ # "01234abc56789".strip("0-9") # "abc"
4674
+ # "01234abc56789".strip("0-9", "^4-6") # "4abc56"
4675
+ #
4577
4676
  # Related: see [Converting to New
4578
4677
  # String](rdoc-ref:String@Converting+to+New+String).
4579
4678
  #
@@ -4581,7 +4680,7 @@ class String
4581
4680
 
4582
4681
  # <!--
4583
4682
  # rdoc-file=string.c
4584
- # - strip! -> self or nil
4683
+ # - strip!(*selectors) -> self or nil
4585
4684
  # -->
4586
4685
  # Like String#strip, except that:
4587
4686
  #
@@ -4742,7 +4841,7 @@ class String
4742
4841
 
4743
4842
  # <!--
4744
4843
  # rdoc-file=string.c
4745
- # - swapcase(mapping) -> new_string
4844
+ # - swapcase(mapping = :ascii) -> new_string
4746
4845
  # -->
4747
4846
  # Returns a string containing the characters in `self`, with cases reversed:
4748
4847
  #
@@ -4751,16 +4850,28 @@ class String
4751
4850
  #
4752
4851
  # Examples:
4753
4852
  #
4754
- # 'Hello World!'.swapcase # => "hELLO wORLD!"
4755
- # 'тест'.swapcase # => "ТЕСТ"
4853
+ # 'Hello'.swapcase # => "hELLO"
4854
+ # 'Straße'.swapcase # => "sTRASSE"
4855
+ # 'Привет'.swapcase # => "пРИВЕТ"
4856
+ # 'RubyGems.org'.swapcase # => "rUBYgEMS.ORG"
4857
+ #
4858
+ # The sizes of `self` and the upcased result may differ:
4756
4859
  #
4757
- # Some characters (and even character sets) do not have casing:
4860
+ # s = 'Straße'
4861
+ # s.size # => 6
4862
+ # s.swapcase # => "sTRASSE"
4863
+ # s.swapcase.size # => 7
4758
4864
  #
4759
- # '12345'.swapcase # => "12345"
4760
- # 'こんにちは'.swapcase # => "こんにちは"
4865
+ # Some characters (and some character sets) do not have upcase and downcase
4866
+ # versions; see [Case Mapping](rdoc-ref:case_mapping.rdoc):
4761
4867
  #
4762
- # The casing may be affected by the given `mapping`; see [Case
4763
- # Mapping](rdoc-ref:case_mapping.rdoc).
4868
+ # s = '1, 2, 3, ...'
4869
+ # s.swapcase == s # => true
4870
+ # s = 'こんにちは'
4871
+ # s.swapcase == s # => true
4872
+ #
4873
+ # The casing is affected by the given `mapping`, which may be `:ascii`, `:fold`,
4874
+ # or `:turkic`; see [Case Mappings](rdoc-ref:case_mapping.rdoc@Case+Mappings).
4764
4875
  #
4765
4876
  # Related: see [Converting to New
4766
4877
  # String](rdoc-ref:String@Converting+to+New+String).
@@ -5149,16 +5260,13 @@ class String
5149
5260
 
5150
5261
  # <!--
5151
5262
  # rdoc-file=string.c
5152
- # - undump -> string
5263
+ # - undump -> new_string
5153
5264
  # -->
5154
- # Returns an unescaped version of `self`:
5155
- #
5156
- # s_orig = "\f\x00\xff\\\"" # => "\f\u0000\xFF\\\""
5157
- # s_dumped = s_orig.dump # => "\"\\f\\x00\\xFF\\\\\\\"\""
5158
- # s_undumped = s_dumped.undump # => "\f\u0000\xFF\\\""
5159
- # s_undumped == s_orig # => true
5265
+ # Inverse of String#dump; returns a copy of `self` with changes of the kinds
5266
+ # made by String#dump "undone."
5160
5267
  #
5161
- # Related: String#dump (inverse of String#undump).
5268
+ # Related: see [Converting to New
5269
+ # String](rdoc-ref:String@Converting+to+New+String).
5162
5270
  #
5163
5271
  def undump: () -> String
5164
5272
 
@@ -5179,21 +5287,22 @@ class String
5179
5287
  #
5180
5288
  # The encoding of `self` must be one of:
5181
5289
  #
5182
- # * Encoding::UTF_8
5183
- # * Encoding::UTF_16BE
5184
- # * Encoding::UTF_16LE
5185
- # * Encoding::UTF_32BE
5186
- # * Encoding::UTF_32LE
5187
- # * Encoding::GB18030
5188
- # * Encoding::UCS_2BE
5189
- # * Encoding::UCS_4BE
5290
+ # * `Encoding::UTF_8`.
5291
+ # * `Encoding::UTF_16BE`.
5292
+ # * `Encoding::UTF_16LE`.
5293
+ # * `Encoding::UTF_32BE`.
5294
+ # * `Encoding::UTF_32LE`.
5295
+ # * `Encoding::GB18030`.
5296
+ # * `Encoding::UCS_2BE`.
5297
+ # * `Encoding::UCS_4BE`.
5190
5298
  #
5191
5299
  # Examples:
5192
5300
  #
5193
- # "a\u0300".unicode_normalize # => "a"
5194
- # "\u00E0".unicode_normalize(:nfd) # => "a "
5301
+ # "a\u0300".unicode_normalize # => "à" # Lowercase 'a' with grave accens.
5302
+ # "a\u0300".unicode_normalize(:nfd) # => "à" # Same.
5195
5303
  #
5196
- # Related: String#unicode_normalize!, String#unicode_normalized?.
5304
+ # Related: see [Converting to New
5305
+ # String](rdoc-ref:String@Converting+to+New+String).
5197
5306
  #
5198
5307
  def unicode_normalize: (?:nfc | :nfd | :nfkc | :nfkd form) -> self
5199
5308
 
@@ -5239,7 +5348,7 @@ class String
5239
5348
  # - unpack(template, offset: 0) -> array
5240
5349
  # -->
5241
5350
  # Extracts data from `self` to form new objects; see [Packed
5242
- # Data](rdoc-ref:packed_data.rdoc).
5351
+ # Data](rdoc-ref:language/packed_data.rdoc).
5243
5352
  #
5244
5353
  # With a block given, calls the block with each unpacked object.
5245
5354
  #
@@ -5256,7 +5365,7 @@ class String
5256
5365
  # - unpack1(template, offset: 0) -> object
5257
5366
  # -->
5258
5367
  # Like String#unpack with no block, but unpacks and returns only the first
5259
- # extracted object. See [Packed Data](rdoc-ref:packed_data.rdoc).
5368
+ # extracted object. See [Packed Data](rdoc-ref:language/packed_data.rdoc).
5260
5369
  #
5261
5370
  # Related: see [Converting to
5262
5371
  # Non-String](rdoc-ref:String@Converting+to+Non--5CString).
@@ -5265,17 +5374,35 @@ class String
5265
5374
 
5266
5375
  # <!--
5267
5376
  # rdoc-file=string.c
5268
- # - upcase(mapping) -> string
5377
+ # - upcase(mapping = :ascii) -> new_string
5269
5378
  # -->
5270
- # Returns a string containing the upcased characters in `self`:
5379
+ # Returns a new string containing the upcased characters in `self`:
5271
5380
  #
5272
- # s = 'Hello World!' # => "Hello World!"
5273
- # s.upcase # => "HELLO WORLD!"
5381
+ # 'hello'.upcase # => "HELLO"
5382
+ # 'straße'.upcase # => "STRASSE"
5383
+ # 'привет'.upcase # => "ПРИВЕТ"
5384
+ # 'RubyGems.org'.upcase # => "RUBYGEMS.ORG"
5385
+ #
5386
+ # The sizes of `self` and the upcased result may differ:
5387
+ #
5388
+ # s = 'Straße'
5389
+ # s.size # => 6
5390
+ # s.upcase # => "STRASSE"
5391
+ # s.upcase.size # => 7
5392
+ #
5393
+ # Some characters (and some character sets) do not have upcase and downcase
5394
+ # versions; see [Case Mapping](rdoc-ref:case_mapping.rdoc):
5395
+ #
5396
+ # s = '1, 2, 3, ...'
5397
+ # s.upcase == s # => true
5398
+ # s = 'こんにちは'
5399
+ # s.upcase == s # => true
5274
5400
  #
5275
- # The casing may be affected by the given `mapping`; see [Case
5276
- # Mapping](rdoc-ref:case_mapping.rdoc).
5401
+ # The casing is affected by the given `mapping`, which may be `:ascii`, `:fold`,
5402
+ # or `:turkic`; see [Case Mappings](rdoc-ref:case_mapping.rdoc@Case+Mappings).
5277
5403
  #
5278
- # Related: String#upcase!, String#downcase, String#downcase!.
5404
+ # Related: see [Converting to New
5405
+ # String](rdoc-ref:String@Converting+to+New+String).
5279
5406
  #
5280
5407
  def upcase: () -> String
5281
5408
  | (:ascii | :lithuanian | :turkic) -> String
@@ -5286,18 +5413,12 @@ class String
5286
5413
  # rdoc-file=string.c
5287
5414
  # - upcase!(mapping) -> self or nil
5288
5415
  # -->
5289
- # Upcases the characters in `self`; returns `self` if any changes were made,
5290
- # `nil` otherwise:
5291
- #
5292
- # s = 'Hello World!' # => "Hello World!"
5293
- # s.upcase! # => "HELLO WORLD!"
5294
- # s # => "HELLO WORLD!"
5295
- # s.upcase! # => nil
5416
+ # Like String#upcase, except that:
5296
5417
  #
5297
- # The casing may be affected by the given `mapping`; see [Case
5298
- # Mapping](rdoc-ref:case_mapping.rdoc).
5418
+ # * Changes character casings in `self` (not in a copy of `self`).
5419
+ # * Returns `self` if any changes are made, `nil` otherwise.
5299
5420
  #
5300
- # Related: String#upcase, String#downcase, String#downcase!.
5421
+ # Related: See [Modifying](rdoc-ref:String@Modifying).
5301
5422
  #
5302
5423
  def upcase!: () -> self?
5303
5424
  | (:ascii | :lithuanian | :turkic) -> self?
@@ -5314,20 +5435,28 @@ class String
5314
5435
  # `self.succ`, and so on; the sequence terminates when value `other_string` is
5315
5436
  # reached; returns `self`:
5316
5437
  #
5317
- # 'a8'.upto('b6') {|s| print s, ' ' } # => "a8"
5438
+ # a = []
5439
+ # 'a'.upto('f') {|c| a.push(c) }
5440
+ # a # => ["a", "b", "c", "d", "e", "f"]
5318
5441
  #
5319
- # Output:
5442
+ # a = []
5443
+ # 'Ж'.upto('П') {|c| a.push(c) }
5444
+ # a # => ["Ж", "З", "И", "Й", "К", "Л", "М", "Н", "О", "П"]
5320
5445
  #
5321
- # a8 a9 b0 b1 b2 b3 b4 b5 b6
5446
+ # a = []
5447
+ # 'よ'.upto('ろ') {|c| a.push(c) }
5448
+ # a # => ["よ", "ら", "り", "る", "れ", "ろ"]
5449
+ #
5450
+ # a = []
5451
+ # 'a8'.upto('b6') {|c| a.push(c) }
5452
+ # a # => ["a8", "a9", "b0", "b1", "b2", "b3", "b4", "b5", "b6"]
5322
5453
  #
5323
5454
  # If argument `exclusive` is given as a truthy object, the last value is
5324
5455
  # omitted:
5325
5456
  #
5326
- # 'a8'.upto('b6', true) {|s| print s, ' ' } # => "a8"
5327
- #
5328
- # Output:
5329
- #
5330
- # a8 a9 b0 b1 b2 b3 b4 b5
5457
+ # a = []
5458
+ # 'a'.upto('f', true) {|c| a.push(c) }
5459
+ # a # => ["a", "b", "c", "d", "e"]
5331
5460
  #
5332
5461
  # If `other_string` would not be reached, does not call the block:
5333
5462
  #
@@ -5338,6 +5467,8 @@ class String
5338
5467
  #
5339
5468
  # 'a8'.upto('b6') # => #<Enumerator: "a8":upto("b6")>
5340
5469
  #
5470
+ # Related: see [Iterating](rdoc-ref:String@Iterating).
5471
+ #
5341
5472
  def upto: (string other_string, ?boolish exclusive) -> Enumerator[String, self]
5342
5473
  | (string other_string, ?boolish exclusive) { (String s) -> void } -> self
5343
5474
 
@@ -5345,11 +5476,14 @@ class String
5345
5476
  # rdoc-file=string.c
5346
5477
  # - valid_encoding? -> true or false
5347
5478
  # -->
5348
- # Returns `true` if `self` is encoded correctly, `false` otherwise:
5479
+ # Returns whether `self` is encoded correctly:
5349
5480
  #
5350
- # "\xc2\xa1".force_encoding(Encoding::UTF_8).valid_encoding? # => true
5351
- # "\xc2".force_encoding(Encoding::UTF_8).valid_encoding? # => false
5352
- # "\x80".force_encoding(Encoding::UTF_8).valid_encoding? # => false
5481
+ # s = 'Straße'
5482
+ # s.valid_encoding? # => true
5483
+ # s.encoding # => #<Encoding:UTF-8>
5484
+ # s.force_encoding(Encoding::ASCII).valid_encoding? # => false
5485
+ #
5486
+ # Related: see [Querying](rdoc-ref:String@Querying).
5353
5487
  #
5354
5488
  def valid_encoding?: () -> bool
5355
5489
  end