core/string.rbs in rbs-3.3.2 vs core/string.rbs in rbs-3.4.0.pre.1

- old
+ new

@@ -79,25 +79,25 @@ # # * `\n` (*n* a non-negative integer) refers to `$n`. # * `\k<name>` refers to the named capture `name`. # # -# See regexp.rdoc for details. +# See Regexp for details. # # Note that within the string `replacement`, a character combination such as # `$&` is treated as ordinary text, and not as a special match variable. # However, you may refer to some special match variables using these # combinations: # # * `\&` and `\0` correspond to `$&`, which contains the complete matched # text. # * `\'` corresponds to `$'`, which contains string after match. # * `\`` corresponds to `$``, which contains string before match. -# * `+` corresponds to `$+`, which contains last capture group. +# * `\+` corresponds to `$+`, which contains last capture group. # # -# See regexp.rdoc for details. +# See Regexp for details. # # Note that `\\\` is interpreted as an escape, i.e., a single backslash. # # Note also that a string literal consumes backslashes. See [String # Literals](rdoc-ref:syntax/literals.rdoc@String+Literals) for details about @@ -277,11 +277,11 @@ # s[/[aeiou](.)\1/] # => "ell" # s[/[aeiou](.)\1/, 0] # => "ell" # # If argument `capture` is given and not `0`, it should be either an capture # group index (integer) or a capture group name (string or symbol); the slice is -# the specified capture (see Regexp@Capturing): +# the specified capture (see Regexp@Groups+and+Captures): # # s = 'hello there' # s[/[aeiou](.)\1/, 1] # => "l" # s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "non_vowel"] # => "l" # s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, :vowel] # => "e" @@ -627,10 +627,13 @@ # calls to #succ. # class String include Comparable + # A `selector` is a special type of string, used within methods like `String#tr`. + type selector = string + # <!-- # rdoc-file=string.c # - String.try_convert(object) -> object, new_string, or nil # --> # If `object` is a String object, returns `object`. @@ -640,16 +643,83 @@ # # Returns `nil` if `object` does not respond to `:to_str`. # # Raises an exception unless `object.to_str` returns a String object. # - def self.try_convert: (untyped obj) -> String? + def self.try_convert: (String object) -> String # technically will return `object` unchanged. + | (_ToStr object) -> String + | (untyped object) -> String? - public + # <!-- + # rdoc-file=string.c + # - String.new(string = '', **opts) -> new_string + # --> + # Returns a new String that is a copy of `string`. + # + # With no arguments, returns the empty string with the Encoding `ASCII-8BIT`: + # + # s = String.new + # s # => "" + # s.encoding # => #<Encoding:ASCII-8BIT> + # + # With optional argument `string` and no keyword arguments, returns a copy of + # `string` with the same encoding: + # + # String.new('foo') # => "foo" + # String.new('тест') # => "тест" + # String.new('こんにちは') # => "こんにちは" + # + # (Unlike String.new, a [string + # literal](rdoc-ref:syntax/literals.rdoc@String+Literals) like `''` or a [here + # document literal](rdoc-ref:syntax/literals.rdoc@Here+Document+Literals) always + # has [script encoding](rdoc-ref:encodings.rdoc@Script+Encoding).) + # + # With optional keyword argument `encoding`, returns a copy of `string` with the + # specified encoding; the `encoding` may be an Encoding object, an encoding + # name, or an encoding name alias: + # + # String.new('foo', encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII> + # String.new('foo', encoding: 'US-ASCII').encoding # => #<Encoding:US-ASCII> + # String.new('foo', encoding: 'ASCII').encoding # => #<Encoding:US-ASCII> + # + # The given encoding need not be valid for the string's content, and that + # validity is not checked: + # + # s = String.new('こんにちは', encoding: 'ascii') + # s.valid_encoding? # => false + # + # But the given `encoding` itself is checked: + # + # String.new('foo', encoding: 'bar') # Raises ArgumentError. + # + # With optional keyword argument `capacity`, returns a copy of `string` (or an + # empty string, if `string` is not given); the given `capacity` is advisory + # only, and may or may not set the size of the internal buffer, which may in + # turn affect performance: + # + # String.new(capacity: 1) + # String.new('foo', capacity: 4096) + # + # The `string`, `encoding`, and `capacity` arguments may all be used together: + # + # String.new('hello', encoding: 'UTF-8', capacity: 25) + # + def initialize: (?string source, ?encoding: encoding?, ?capacity: int?) -> self # <!-- # rdoc-file=string.c + # - replace(other_string) -> self + # --> + # Replaces the contents of `self` with the contents of `other_string`: + # + # s = 'foo' # => "foo" + # s.replace('bar') # => "bar" + # + alias initialize_copy replace + + # <!-- + # rdoc-file=string.c # - string % object -> new_string # --> # Returns the result of formatting `object` into the format specification `self` # (see Kernel#sprintf for formatting details): # @@ -660,12 +730,12 @@ # # "%-5s: %016x" % [ "ID", self.object_id ] # => "ID : 00002b054ec93168" # "foo = %{foo}" % {foo: 'bar'} # => "foo = bar" # "foo = %{foo}, baz = %{baz}" % {foo: 'bar', baz: 'bat'} # => "foo = bar, baz = bat" # - def %: (Hash[Symbol, untyped]) -> String - | (Array[untyped]) -> String + def %: (array[untyped] positional_args) -> String + | (hash[Symbol, untyped] named_args) -> String | (untyped arg) -> String # <!-- # rdoc-file=string.c # - string * integer -> new_string @@ -673,44 +743,52 @@ # Returns a new String containing `integer` copies of `self`: # # "Ho! " * 3 # => "Ho! Ho! Ho! " # "Ho! " * 0 # => "" # - def *: (int n) -> String + def *: (int amount) -> String # <!-- # rdoc-file=string.c # - string + other_string -> new_string # --> # Returns a new String containing `other_string` concatenated to `self`: # # "Hello from " + self.to_s # => "Hello from main" # - def +: (string other_str) -> String + def +: (string other_string) -> String # <!-- # rdoc-file=string.c # - +string -> new_string or self # --> # Returns `self` if `self` is not frozen. # # Otherwise returns `self.dup`, which is not frozen. # - def +@: () -> String + def +@: () -> self # <!-- # rdoc-file=string.c # - -string -> frozen_string + # - dedup -> frozen_string # --> # Returns a frozen, possibly pre-existing copy of the string. # # The returned String will be deduplicated as long as it does not have any # instance variables set on it and is not a String subclass. # - # String#dedup is an alias for String#-@. + # Note that `-string` variant is more convenient for defining constants: # - def -@: () -> String + # FILENAME = -'config/database.yml' + # + # while `dedup` is better suitable for using the method in chains of + # calculations: + # + # @url_list.concat(urls.map(&:dedup)) + # + def -@: () -> self # <!-- # rdoc-file=string.c # - string << object -> string # --> @@ -726,11 +804,11 @@ # s = 'foo' # s << 33 # => "foo!" # # Related: String#concat, which takes multiple arguments. # - def <<: (string | Integer str_or_codepoint) -> String + def <<: (string | Integer str_or_codepoint) -> self # <!-- # rdoc-file=string.c # - string <=> other_string -> -1, 0, 1, or nil # --> @@ -749,12 +827,12 @@ # 'food' <=> 'foo' # => 1 # 'FOO' <=> 'foo' # => -1 # 'foo' <=> 'FOO' # => 1 # 'foo' <=> 1 # => nil # - def <=>: (string other) -> Integer - | (untyped other) -> Integer? + def <=>: (string) -> (-1 | 0 | 1) + | (untyped) -> (-1 | 0 | 1)? # <!-- # rdoc-file=string.c # - string == object -> true or false # - string === object -> true or false @@ -771,11 +849,11 @@ # "\u{e4 f6 fc}".encode("ISO-8859-1") == ("\u{c4 d6 dc}") # => false # # If `object` is not an instance of String but responds to `to_str`, then the # two strings are compared using `object.==`. # - def ==: (untyped obj) -> bool + def ==: (untyped other) -> bool # <!-- rdoc-file=string.c --> # Returns `true` if `object` has the same length and content; as `self`; `false` # otherwise: # @@ -788,11 +866,11 @@ # "\u{e4 f6 fc}".encode("ISO-8859-1") == ("\u{c4 d6 dc}") # => false # # If `object` is not an instance of String but responds to `to_str`, then the # two strings are compared using `object.==`. # - def ===: (untyped obj) -> bool + alias === == # <!-- # rdoc-file=string.c # - string =~ regexp -> integer or nil # - string =~ object -> integer or nil @@ -802,11 +880,11 @@ # # 'foo' =~ /f/ # => 0 # 'foo' =~ /o/ # => 1 # 'foo' =~ /x/ # => nil # - # Note: also updates Regexp@Special+global+variables. + # Note: also updates Regexp@Global+Variables. # # If the given `object` is not a Regexp, returns the value returned by `object # =~ self`. # # Note that `string =~ regexp` is different from `regexp =~ string` (see @@ -816,12 +894,17 @@ # "no. 9" =~ /(?<number>\d+)/ # number # => nil (not assigned) # /(?<number>\d+)/ =~ "no. 9" # number #=> "9" # - def =~: (untyped obj) -> Integer? + def =~: (Regexp regex) -> Integer? + | [T] (_MatchAgainst[self, T] object) -> T + interface _MatchAgainst[O, T] + def =~: (O string) -> T + end + # <!-- # rdoc-file=string.c # - string[index] -> new_string or nil # - string[start, length] -> new_string or nil # - string[range] -> new_string or nil @@ -829,16 +912,14 @@ # - string[substring] -> new_string or nil # --> # Returns the substring of `self` specified by the arguments. See examples at # [String Slices](rdoc-ref:String@String+Slices). # - def []: (int index) -> String? - | (int start, int length) -> String? - | (Range[Integer] | Range[Integer?] range) -> String? - | (Regexp regexp) -> String? - | (Regexp regexp, int | String capture) -> String? - | (String match_str) -> String? + def []: (int start, ?int length) -> String? + | (range[int?] range) -> String? + | (Regexp regexp, ?MatchData::capture backref) -> String? + | (String substring) -> String? # <!-- # rdoc-file=string.c # - string[index] = new_string # - string[start, length] = new_string @@ -861,19 +942,16 @@ # s[/e$/] = 'ly' # => "ly" # s # => "finally" # s['lly'] = 'ncial' # => "ncial" # s # => "financial" # - # String#slice is an alias for String#[]. - # - def []=: (int pos, String new_str) -> String - | (int begin_pos, int end_pos, String new_str) -> String - | (Range[Integer] | Range[Integer?] range, String new_str) -> String - | (Regexp regexp, String new_str) -> String - | (Regexp regexp, int capture, String new_str) -> String - | (Regexp regexp, String name, String new_str) -> String - | (String other_str, String new_str) -> String + def []=: [T < _ToStr] (int index, T replacement) -> T + | [T < _ToStr] (int start, int length, T replacement) -> T + | [T < _ToStr] (range[int?] range, T replacement) -> T + | [T < _ToStr] (Regexp regexp, T replacement) -> T + | [T < _ToStr] (Regexp regexp, MatchData::capture backref, T replacement) -> T + | [T < _ToStr] (String substring, T replacement) -> T # <!-- # rdoc-file=string.c # - ascii_only? -> true or false # --> @@ -943,11 +1021,11 @@ # If `offset` does not land on character (codepoint) boundary, `IndexError` is # raised. # # Related: String#index, String#byterindex. # - def byteindex: (Regexp | string substr_or_regexp, ?int offset) -> Integer? + def byteindex: (Regexp | string pattern, ?int offset) -> Integer? # <!-- # rdoc-file=string.c # - byterindex(substring, offset = self.bytesize) -> integer or nil # - byterindex(regexp, offset = self.bytesize) -> integer or nil @@ -1004,11 +1082,11 @@ # If `offset` does not land on character (codepoint) boundary, `IndexError` is # raised. # # Related: String#byteindex. # - def byterindex: (Regexp | string substr_or_regexp, ?int offset) -> Integer? + def byterindex: (Regexp | string pattern, ?int offset) -> Integer? # <!-- # rdoc-file=string.c # - bytes -> array_of_bytes # --> @@ -1018,11 +1096,11 @@ # 'тест'.bytes # => [209, 130, 208, 181, 209, 129, 209, 130] # 'こんにちは'.bytes # # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175] # def bytes: () -> Array[Integer] - | () { (Integer byte) -> void } -> String + | () { (Integer byte) -> void } -> self # <!-- # rdoc-file=string.c # - bytesize -> integer # --> @@ -1080,28 +1158,38 @@ # # s.encoding # => #<Encoding:UTF-8> # s.byteslice(4).encoding # => #<Encoding:UTF-8> # def byteslice: (int start, ?int length) -> String? - | (Range[Integer] | Range[Integer?] range) -> String? + | (range[int?] range) -> String? # <!-- # rdoc-file=string.c # - bytesplice(index, length, str) -> string - # - bytesplice(range, str) -> string + # - bytesplice(index, length, str, str_index, str_length) -> string + # - bytesplice(range, str) -> string + # - bytesplice(range, str, str_range) -> string # --> # Replaces some or all of the content of `self` with `str`, and returns `self`. # The portion of the string affected is determined using the same criteria as # String#byteslice, except that `length` cannot be omitted. If the replacement # string is not the same length as the text it is replacing, the string will be - # adjusted accordingly. The form that take an Integer will raise an IndexError - # if the value is out of range; the Range form will raise a RangeError. If the - # beginning or ending offset does not land on character (codepoint) boundary, an - # IndexError will be raised. + # adjusted accordingly. # - def bytesplice: (int index, int length, string str) -> String - | (Range[int?], string str) -> String + # If `str_index` and `str_length`, or `str_range` are given, the content of + # `self` is replaced by str.byteslice(str_index, str_length) or + # str.byteslice(str_range); however the substring of `str` is not allocated as a + # new string. + # + # The form that take an Integer will raise an IndexError if the value is out of + # range; the Range form will raise a RangeError. If the beginning or ending + # offset does not land on character (codepoint) boundary, an IndexError will be + # raised. + # + def bytesplice: (int start, int length, string str) -> String + | (int start, int length, string str, int str_start, int str_length) -> String + | (range[int?] range, string str, ?range[int?] str_range) -> String # <!-- # rdoc-file=string.c # - capitalize(*options) -> string # --> @@ -1136,14 +1224,14 @@ # The casing may be affected by the given `options`; see [Case # Mapping](rdoc-ref:case_mapping.rdoc). # # Related: String#capitalize. # - def capitalize!: () -> String? - | (:ascii | :lithuanian | :turkic) -> String? - | (:lithuanian, :turkic) -> String? - | (:turkic, :lithuanian) -> String? + def capitalize!: () -> self? + | (:ascii | :lithuanian | :turkic) -> self? + | (:lithuanian, :turkic) -> self? + | (:turkic, :lithuanian) -> self? # <!-- # rdoc-file=string.c # - casecmp(other_string) -> -1, 0, 1, or nil # --> @@ -1166,11 +1254,12 @@ # # See [Case Mapping](rdoc-ref:case_mapping.rdoc). # # Related: String#casecmp?. # - def casecmp: (untyped other) -> Integer? + def casecmp: (string other) -> (-1 | 0 | 1) + | (untyped) -> (-1 | 0 | 1)? # <!-- # rdoc-file=string.c # - casecmp?(other_string) -> true, false, or nil # --> @@ -1189,11 +1278,12 @@ # # See [Case Mapping](rdoc-ref:case_mapping.rdoc). # # Related: String#casecmp. # - def casecmp?: (untyped other) -> bool? + def casecmp?: (string other) -> bool + | (untyped) -> bool? # <!-- # rdoc-file=string.c # - center(size, pad_string = ' ') -> new_string # --> @@ -1214,11 +1304,11 @@ # 'hello'.center(5) # => "hello" # 'hello'.center(1) # => "hello" # # Related: String#ljust, String#rjust. # - def center: (int width, ?string padstr) -> String + def center: (int width, ?string pad_string) -> String # <!-- # rdoc-file=string.c # - chars -> array_of_characters # --> @@ -1227,11 +1317,11 @@ # 'hello'.chars # => ["h", "e", "l", "l", "o"] # 'тест'.chars # => ["т", "е", "с", "т"] # 'こんにちは'.chars # => ["こ", "ん", "に", "ち", "は"] # def chars: () -> Array[String] - | () { (String char) -> void } -> String + | () { (String char) -> void } -> self # <!-- # rdoc-file=string.c # - chomp(line_sep = $/) -> new_string # --> @@ -1262,20 +1352,22 @@ # separator if there is one: # # 'abcd'.chomp('d') # => "abc" # 'abcdd'.chomp('d') # => "abcd" # - def chomp: (?string separator) -> String + def chomp: (?string? separator) -> String # <!-- # rdoc-file=string.c # - chomp!(line_sep = $/) -> self or nil # --> # Like String#chomp, but modifies `self` in place; returns `nil` if no # modification made, `self` otherwise. # - def chomp!: (?string separator) -> String? + def chomp!: (nil) -> nil + # | (?string separator) -> self? # https://github.com/ruby/rbs/pull/1672#discussion_r1423324796 + | (?string? separator) -> self? # <!-- # rdoc-file=string.c # - chop -> new_string # --> @@ -1307,11 +1399,11 @@ # Like String#chop, but modifies `self` in place; returns `nil` if `self` is # empty, `self` otherwise. # # Related: String#chomp!. # - def chop!: () -> String? + def chop!: () -> self? # <!-- # rdoc-file=string.c # - chr -> string # --> @@ -1329,11 +1421,11 @@ # Removes the contents of `self`: # # s = 'foo' # => "foo" # s.clear # => "" # - def clear: () -> String + def clear: () -> self # <!-- # rdoc-file=string.c # - codepoints -> array_of_integers # --> @@ -1342,12 +1434,12 @@ # # 'hello'.codepoints # => [104, 101, 108, 108, 111] # 'тест'.codepoints # => [1090, 1077, 1089, 1090] # 'こんにちは'.codepoints # => [12371, 12435, 12395, 12385, 12399] # - def codepoints: () -> ::Array[Integer] - | () { (Integer codepoint) -> void } -> String + def codepoints: () -> Array[Integer] + | () { (Integer codepoint) -> void } -> self # <!-- # rdoc-file=string.c # - concat(*objects) -> string # --> @@ -1363,11 +1455,11 @@ # s = 'foo' # s.concat(32, 'bar', 32, 'baz') # => "foo bar baz" # # Related: String#<<, which takes a single argument. # - def concat: (*string | Integer str_or_codepoint) -> String + def concat: (*string | Integer string_or_codepoints) -> self # <!-- # rdoc-file=string.c # - count(*selectors) -> integer # --> @@ -1387,11 +1479,11 @@ # c = "hello world\\r\\n" # c.count "\\" #=> 2 # c.count "\\A" #=> 0 # c.count "X-\\w" #=> 3 # - def count: (string other_str, *string other_strs) -> Integer + def count: (selector selector_0, *selector more_selectors) -> Integer # <!-- # rdoc-file=string.c # - crypt(salt_str) -> new_string # --> @@ -1451,12 +1543,19 @@ # Returns a frozen, possibly pre-existing copy of the string. # # The returned String will be deduplicated as long as it does not have any # instance variables set on it and is not a String subclass. # - # String#dedup is an alias for String#-@. + # Note that `-string` variant is more convenient for defining constants: # + # FILENAME = -'config/database.yml' + # + # while `dedup` is better suitable for using the method in chains of + # calculations: + # + # @url_list.concat(urls.map(&:dedup)) + # alias dedup -@ # <!-- # rdoc-file=string.c # - delete(*selectors) -> new_string @@ -1468,20 +1567,20 @@ # "hello".delete "l","lo" #=> "heo" # "hello".delete "lo" #=> "he" # "hello".delete "aeiou", "^e" #=> "hell" # "hello".delete "ej-m" #=> "ho" # - def delete: (string other_str, *string other_strs) -> String + def delete: (selector selector_0, *selector more_selectors) -> String # <!-- # rdoc-file=string.c # - delete!(*selectors) -> self or nil # --> # Like String#delete, but modifies `self` in place. Returns `self` if any # changes were made, `nil` otherwise. # - def delete!: (string other_str, *string other_strs) -> String? + def delete!: (selector selector_0, *selector more_selectors) -> self? # <!-- # rdoc-file=string.c # - delete_prefix(prefix) -> new_string # --> @@ -1501,11 +1600,11 @@ # - delete_prefix!(prefix) -> self or nil # --> # Like String#delete_prefix, except that `self` is modified in place. Returns # `self` if the prefix is removed, `nil` otherwise. # - def delete_prefix!: (string prefix) -> String? + def delete_prefix!: (string prefix) -> self? # <!-- # rdoc-file=string.c # - delete_suffix(suffix) -> new_string # --> @@ -1525,11 +1624,11 @@ # - delete_suffix!(suffix) -> self or nil # --> # Like String#delete_suffix, except that `self` is modified in place. Returns # `self` if the suffix is removed, `nil` otherwise. # - def delete_suffix!: (string suffix) -> String? + def delete_suffix!: (string suffix) -> self? # <!-- # rdoc-file=string.c # - downcase(*options) -> string # --> @@ -1563,14 +1662,14 @@ # The casing may be affected by the given `options`; see [Case # Mapping](rdoc-ref:case_mapping.rdoc). # # Related: String#downcase, String#upcase, String#upcase!. # - def downcase!: () -> String? - | (:ascii | :fold | :lithuanian | :turkic) -> String? - | (:lithuanian, :turkic) -> String? - | (:turkic, :lithuanian) -> String? + def downcase!: () -> self? + | (:ascii | :fold | :lithuanian | :turkic) -> self? + | (:lithuanian, :turkic) -> self? + | (:turkic, :lithuanian) -> self? # <!-- # rdoc-file=string.c # - dump -> string # --> @@ -1605,12 +1704,12 @@ # 209 130 208 181 209 129 209 130 # 227 129 147 227 130 147 227 129 171 227 129 161 227 129 175 # # Returns an enumerator if no block is given. # - def each_byte: () { (Integer byte) -> void } -> self - | () -> ::Enumerator[Integer, self] + def each_byte: () -> Enumerator[Integer, self] + | () { (Integer byte) -> void } -> self # <!-- # rdoc-file=string.c # - each_char {|c| ... } -> self # - each_char -> enumerator @@ -1631,12 +1730,12 @@ # т е с т # こ ん に ち は # # Returns an enumerator if no block is given. # - def each_char: () { (String char) -> void } -> self - | () -> ::Enumerator[String, self] + def each_char: () -> Enumerator[String, self] + | () { (String char) -> void } -> self # <!-- # rdoc-file=string.c # - each_codepoint {|integer| ... } -> self # - each_codepoint -> enumerator @@ -1657,12 +1756,12 @@ # 1090 1077 1089 1090 # 12371 12435 12395 12385 12399 # # Returns an enumerator if no block is given. # - def each_codepoint: () { (Integer codepoint) -> void } -> self - | () -> ::Enumerator[Integer, self] + def each_codepoint: () -> Enumerator[Integer, self] + | () { (Integer codepoint) -> void } -> self # <!-- # rdoc-file=string.c # - each_grapheme_cluster {|gc| ... } -> self # - each_grapheme_cluster -> enumerator @@ -1679,12 +1778,12 @@ # # ä - p q r - b̈ - x y z - c̈ # # Returns an enumerator if no block is given. # - def each_grapheme_cluster: () { (String grapheme) -> void } -> self - | () -> ::Enumerator[String, self] + def each_grapheme_cluster: () -> Enumerator[String, self] + | () { (String grapheme_cluter) -> void } -> self # <!-- # rdoc-file=string.c # - each_line(line_sep = $/, chomp: false) {|substring| ... } -> self # - each_line(line_sep = $/, chomp: false) -> enumerator @@ -1745,12 +1844,12 @@ # "This is the first line.\nThis is line two.\n\n" # "This is line four.\nThis is line five.\n" # # With no block given, returns an enumerator. # - def each_line: (?string separator, ?chomp: boolish) { (String line) -> void } -> self - | (?string separator, ?chomp: boolish) -> Enumerator[String, self] + def each_line: (?string? separator, ?chomp: boolish) -> Enumerator[String, self] + | (?string? separator, ?chomp: boolish) { (String line) -> void } -> self # <!-- # rdoc-file=string.c # - empty? -> true or false # --> @@ -1761,11 +1860,11 @@ # "".empty? # => true # def empty?: () -> bool # <!-- - # rdoc-file=transcode.rdoc + # rdoc-file=transcode.c # - encode(dst_encoding = Encoding.default_internal, **enc_opts) -> string # - encode(dst_encoding, src_encoding, **enc_opts) -> string # --> # Returns a copy of `self` transcoded as determined by `dst_encoding`. By # default, raises an exception if `self` contains an invalid byte or a character @@ -1807,20 +1906,56 @@ # t.encoding # => #<Encoding:UTF-8> # # Optional keyword arguments `enc_opts` specify encoding options; see [Encoding # Options](rdoc-ref:encodings.rdoc@Encoding+Options). # - 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 + # Please note that, unless `invalid: :replace` option is given, conversion from + # an encoding `enc` to the same encoding `enc` (independent of whether `enc` is + # given explicitly or implicitly) is a no-op, i.e. the string is simply copied + # without any changes, and no exceptions are raised, even if there are invalid + # bytes. + # + def encode: ( + ?encoding source_encoding, + ?encoding? from_encoding, + ?invalid: :replace ?, + ?undef: :replace ?, + ?replace: string?, + ?xml: (:text | :attr)?, + ?newline: (:universal | :crlf | :cr | :lf)?, + ?universal_newline: boolish, + ?cr_newline: boolish, + ?crlf_newline: boolish, + ?lf_newline: boolish, + ?fallback: ^(String) -> string? | Method | _EncodeFallbackAref + ) -> instance + interface _EncodeFallbackAref + def []: (String) -> string? + end + # <!-- # rdoc-file=transcode.c # - encode!(dst_encoding = Encoding.default_internal, **enc_opts) -> self # - encode!(dst_encoding, src_encoding, **enc_opts) -> self # --> # Like #encode, but applies encoding changes to `self`; returns `self`. # - 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 + def encode!: ( + ?encoding source_encoding, + ?encoding? from_encoding, + ?invalid: :replace ?, + ?undef: :replace ?, + ?replace: string?, + ?xml: (:text | :attr)?, + ?newline: (:universal | :crlf | :cr | :lf)?, + ?universal_newline: boolish, + ?cr_newline: boolish, + ?crlf_newline: boolish, + ?lf_newline: boolish, + ?fallback: ^(String) -> string? | Method | _EncodeFallbackAref + ) -> self # <!-- # rdoc-file=string.c # - obj.encoding -> encoding # --> @@ -1886,11 +2021,11 @@ # # s.valid_encoding? # => false # s.force_encoding(Encoding::UTF_8) # => "łał" # s.valid_encoding? # => true # - def force_encoding: (string | Encoding encoding) -> self + def force_encoding: (encoding enc) -> self # <!-- # rdoc-file=string.c # - freeze() # --> @@ -1924,11 +2059,12 @@ # # s = "\u0061\u0308-pqr-\u0062\u0308-xyz-\u0063\u0308" # => "ä-pqr-b̈-xyz-c̈" # s.grapheme_clusters # # => ["ä", "-", "p", "q", "r", "-", "b̈", "-", "x", "y", "z", "-", "c̈"] # - def grapheme_clusters: () -> ::Array[::String] + def grapheme_clusters: () -> Array[String] + | () { (String grapheme_cluter) -> void } -> self # <!-- # rdoc-file=string.c # - gsub(pattern, replacement) -> new_string # - gsub(pattern) {|match| ... } -> new_string @@ -1940,14 +2076,13 @@ # # Returns an Enumerator if no `replacement` and no block given. # # Related: String#sub, String#sub!, String#gsub!. # - def gsub: (Regexp | string pattern, string replacement) -> String - | (Regexp | string pattern, Hash[String, String] hash) -> String + def gsub: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> String + | (Regexp | string pattern) -> Enumerator[String, String] | (Regexp | string pattern) { (String match) -> _ToS } -> String - | (Regexp | string pattern) -> ::Enumerator[String, self] # <!-- # rdoc-file=string.c # - gsub!(pattern, replacement) -> self or nil # - gsub!(pattern) {|match| ... } -> self or nil @@ -1960,14 +2095,13 @@ # # Returns an Enumerator if no `replacement` and no block given. # # Related: String#sub, String#gsub, String#sub!. # - def gsub!: (Regexp | string pattern, string replacement) -> String? - | (Regexp | string pattern, Hash[String, String] hash) -> String? - | (Regexp | string pattern) { (String match) -> _ToS } -> String? - | (Regexp | string pattern) -> ::Enumerator[String, self] + def gsub!: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> self? + | (Regexp | string pattern) -> Enumerator[String, self] + | (Regexp | string pattern) { (String match) -> _ToS } -> self? # <!-- # rdoc-file=string.c # - hash -> integer # --> @@ -2004,11 +2138,11 @@ # s = 'foo' # s.include?('f') # => true # s.include?('fo') # => true # s.include?('food') # => false # - def include?: (string other_str) -> bool + def include?: (string other_string) -> bool # <!-- # rdoc-file=string.c # - index(substring, offset = 0) -> integer or nil # - index(regexp, offset = 0) -> integer or nil @@ -2050,11 +2184,11 @@ # 'foo'.index(/o./, -2) # => 1 # 'foo'.index(/.o/, -2) # => 1 # # Related: String#rindex. # - def index: (Regexp | string substr_or_regexp, ?int offset) -> Integer? + def index: (Regexp | string pattern, ?int offset) -> Integer? # <!-- # rdoc-file=string.c # - insert(index, other_string) -> self # --> @@ -2067,11 +2201,11 @@ # If the Integer `index` is negative, counts backward from the end of `self` and # inserts `other_string` at offset `index+1` (that is, *after* `self[index]`): # # 'foo'.insert(-2, 'bar') # => "fobaro" # - def insert: (int index, string other_str) -> String + def insert: (int index, string other_str) -> self # <!-- # rdoc-file=string.c # - inspect -> string # --> @@ -2119,22 +2253,21 @@ # # 'foo'.bytesize # => 3 # 'тест'.bytesize # => 8 # 'こんにちは'.bytesize # => 15 # - # String#size is an alias for String#length. - # def length: () -> Integer # <!-- # rdoc-file=string.c # - lines(Line_sep = $/, chomp: false) -> array_of_strings # --> # Forms substrings ("lines") of `self` according to the given arguments (see # String#each_line for details); returns the lines in an array. # - def lines: (?string separator, ?chomp: boolish) -> Array[String] + def lines: (?string? separator, ?chomp: boolish) -> Array[String] + | (?string? separator, ?chomp: boolish) { (String line) -> void } -> self # <!-- # rdoc-file=string.c # - ljust(size, pad_string = ' ') -> new_string # --> @@ -2155,11 +2288,11 @@ # 'hello'.ljust(5) # => "hello" # 'hello'.ljust(1) # => "hello" # # Related: String#rjust, String#center. # - def ljust: (int integer, ?string padstr) -> String + def ljust: (int size, ?string pad_string) -> String # <!-- # rdoc-file=string.c # - lstrip -> new_string # --> @@ -2191,11 +2324,11 @@ # - match(pattern, offset = 0) -> matchdata or nil # - match(pattern, offset = 0) {|matchdata| ... } -> object # --> # Returns a MatchData object (or `nil`) based on `self` and the given `pattern`. # - # Note: also updates Regexp@Special+global+variables. + # Note: also updates Regexp@Global+Variables. # # * Computes `regexp` by converting `pattern` (if not already a Regexp). # regexp = Regexp.new(pattern) # # * Computes `matchdata`, which will be either a MatchData object or `nil` @@ -2219,21 +2352,21 @@ # # 'foo'.match(/o/) {|matchdata| matchdata } # => #<MatchData "o"> # 'foo'.match(/x/) {|matchdata| matchdata } # => nil # 'foo'.match(/f/, 1) {|matchdata| matchdata } # => nil # - def match: (Regexp | string pattern, ?int pos) -> MatchData? - | [A] (Regexp | string pattern, ?int pos) { (MatchData) -> A } -> A + def match: (Regexp | string pattern, ?int offset) -> MatchData? + | [T] (Regexp | string pattern, ?int offset) { (MatchData matchdata) -> T } -> T? # <!-- # rdoc-file=string.c # - match?(pattern, offset = 0) -> true or false # --> # Returns `true` or `false` based on whether a match is found for `self` and # `pattern`. # - # Note: does not update Regexp@Special+global+variables. + # Note: does not update Regexp@Global+Variables. # # Computes `regexp` by converting `pattern` (if not already a Regexp). # regexp = Regexp.new(pattern) # # Returns `true` if `self+.match(regexp)` returns a MatchData object, `false` @@ -2245,11 +2378,11 @@ # # If Integer argument `offset` is given, the search begins at index `offset`: # 'foo'.match?('f', 1) # => false # 'foo'.match?('o', 1) # => true # - def match?: (Regexp | string pattern, ?int pos) -> bool + def match?: (Regexp | string pattern, ?int offset) -> bool # <!-- rdoc-file=string.c --> # Returns the successor to `self`. The successor is calculated by incrementing # characters. # @@ -2299,20 +2432,16 @@ # # The successor to an empty String is a new empty String: # # ''.succ # => "" # - # String#next is an alias for String#succ. - # - def next: () -> String + alias next succ # <!-- rdoc-file=string.c --> # Equivalent to String#succ, but modifies `self` in place; returns `self`. # - # String#next! is an alias for String#succ!. - # - def next!: () -> self + alias next! succ! # <!-- # rdoc-file=string.c # - oct -> integer # --> @@ -2371,11 +2500,11 @@ # # 'hello'.partition('x') # => ["hello", "", ""] # # Related: String#rpartition, String#split. # - def partition: (Regexp | string sep_or_regexp) -> [ String, String, String ] + def partition: (Regexp | string pattern) -> [String, String, String] # <!-- # rdoc-file=string.c # - prepend(*other_strings) -> string # --> @@ -2385,19 +2514,19 @@ # s.prepend('bar', 'baz') # => "barbazfoo" # s # => "barbazfoo" # # Related: String#concat. # - def prepend: (*string other_strs) -> String + def prepend: (*string other_strings) -> self # <!-- rdoc-file=string.c --> # Replaces the contents of `self` with the contents of `other_string`: # # s = 'foo' # => "foo" # s.replace('bar') # => "bar" # - def replace: (string other_str) -> String + def replace: (string other_string) -> self # <!-- # rdoc-file=string.c # - reverse -> string # --> @@ -2473,11 +2602,11 @@ # 'foo'.rindex('o', -3) # => nil # 'foo'.rindex('o', -4) # => nil # # Related: String#index. # - def rindex: (string | Regexp substr_or_regexp, ?int pos) -> Integer? + def rindex: (Regexp | string pattern, ?int offset) -> Integer? # <!-- # rdoc-file=string.c # - rjust(size, pad_string = ' ') -> new_string # --> @@ -2498,11 +2627,11 @@ # 'hello'.rjust(5, 'ab') # => "hello" # 'hello'.rjust(1, 'ab') # => "hello" # # Related: String#ljust, String#center. # - def rjust: (int integer, ?string padstr) -> String + def rjust: (int size, ?string pad_string) -> String # <!-- # rdoc-file=string.c # - rpartition(sep) -> [head, match, tail] # --> @@ -2530,11 +2659,11 @@ # # 'hello'.rpartition('x') # => ["", "", "hello"] # # Related: String#partition, String#split. # - def rpartition: (string | Regexp sep_or_regexp) -> [ String, String, String ] + def rpartition: (Regexp | string pattern) -> [String, String, String] # <!-- # rdoc-file=string.c # - rstrip -> new_string # --> @@ -2599,13 +2728,13 @@ # # <<cruel>> <<world>> # rceu lowlr # def scan: (Regexp pattern) -> Array[String | Array[String]] - | (Regexp pattern) { (String | Array[String]) -> void } -> self + | (Regexp pattern) { (String | Array[String] matches) -> void } -> self | (string pattern) -> Array[String] - | (string pattern) { (String) -> void } -> self + | (string pattern) { (String match) -> void } -> self # <!-- # rdoc-file=string.c # - scrub(replacement_string = default_replacement) -> new_string # - scrub{|bytes| ... } -> new_string @@ -2633,23 +2762,23 @@ # Output: # # "\x81" # "\x81" # - def scrub: (?string repl) -> String - | () { (String bytes) -> string } -> String + def scrub: (?string? replacement) -> String + | (?nil) { (String bytes) -> string } -> String # <!-- # rdoc-file=string.c # - scrub! -> self # - scrub!(replacement_string = default_replacement) -> self # - scrub!{|bytes| ... } -> self # --> # Like String#scrub, except that any replacements are made in `self`. # - def scrub!: (?string repl) -> self - | () { (String bytes) -> string } -> self + def scrub!: (?string? replacement) -> self + | (?nil) { (String bytes) -> string } -> self # <!-- # rdoc-file=string.c # - setbyte(index, integer) -> integer # --> @@ -2659,11 +2788,11 @@ # s.setbyte(0, 98) # => 98 # s # => "bbcde" # # Related: String#getbyte. # - def setbyte: (int index, int integer) -> int + def setbyte: [T < _ToInt] (int index, T byte) -> T # <!-- rdoc-file=string.c --> # Returns the count of characters (not bytes) in `self`: # # 'foo'.length # => 3 @@ -2674,12 +2803,10 @@ # # 'foo'.bytesize # => 3 # 'тест'.bytesize # => 8 # 'こんにちは'.bytesize # => 15 # - # String#size is an alias for String#length. - # alias size length # <!-- rdoc-file=string.c --> # Returns the substring of `self` specified by the arguments. See examples at # [String Slices](rdoc-ref:String@String+Slices). @@ -2704,14 +2831,14 @@ # string.slice!(3..6) #=> " is " # string.slice!(/s.*t/) #=> "sa st" # string.slice!("r") #=> "r" # string #=> "Thing" # - def slice!: (int integer, ?int integer) -> String? - | (Range[Integer] | Range[Integer?] range) -> String? - | (Regexp regexp, ?int | String capture) -> String? - | (String other_str) -> String? + def slice!: (int index, ?int length) -> String? + | (range[int?] range) -> String? + | (String substring) -> String? + | (Regexp regexp, ?MatchData::capture backref) -> String? # <!-- # rdoc-file=string.c # - split(field_sep = $;, limit = nil) -> array # - split(field_sep = $;, limit = nil) {|substring| ... } -> self @@ -2795,12 +2922,12 @@ # "def" # "ghi" # # Related: String#partition, String#rpartition. # - def split: (?Regexp | string pattern, ?int limit) -> Array[String] - | (?Regexp | string pattern, ?int limit) { (String) -> void } -> self + def split: (?Regexp | string | nil pattern, ?int limit) -> Array[String] + | (?Regexp | string | nil pattern, ?int limit) { (String substring) -> void } -> self # <!-- # rdoc-file=string.c # - squeeze(*selectors) -> new_string # --> @@ -2814,20 +2941,20 @@ # # "yellow moon".squeeze #=> "yelow mon" # " now is the".squeeze(" ") #=> " now is the" # "putters shoot balls".squeeze("m-z") #=> "puters shot balls" # - def squeeze: (*string other_str) -> String + def squeeze: (*selector selectors) -> String # <!-- # rdoc-file=string.c # - squeeze!(*selectors) -> self or nil # --> # Like String#squeeze, but modifies `self` in place. Returns `self` if any # changes were made, `nil` otherwise. # - def squeeze!: (*string other_str) -> self? + def squeeze!: (*selector selectors) -> self? # <!-- # rdoc-file=string.c # - start_with?(*string_or_regexp) -> true or false # --> @@ -2849,11 +2976,11 @@ # 'тест'.start_with?('т') # => true # 'こんにちは'.start_with?('こ') # => true # # Related: String#end_with?. # - def start_with?: (*string prefixes) -> bool + def start_with?: (*Regexp | string prefixes) -> bool # <!-- # rdoc-file=string.c # - strip -> new_string # --> @@ -2890,11 +3017,11 @@ # # See [Substitution Methods](rdoc-ref:String@Substitution+Methods). # # Related: String#sub!, String#gsub, String#gsub!. # - def sub: (Regexp | string pattern, string | Hash[String, String] replacement) -> String + def sub: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> String | (Regexp | string pattern) { (String match) -> _ToS } -> String # <!-- # rdoc-file=string.c # - sub!(pattern, replacement) -> self or nil @@ -2905,12 +3032,12 @@ # # See [Substitution Methods](rdoc-ref:String@Substitution+Methods). # # Related: String#sub, String#gsub, String#gsub!. # - def sub!: (Regexp | string pattern, string | Hash[String, String] replacement) -> self? - | (Regexp | string pattern) { (String match) -> _ToS } -> String? + def sub!: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> self? + | (Regexp | string pattern) { (String match) -> _ToS } -> self? # <!-- # rdoc-file=string.c # - succ -> new_str # --> @@ -2963,23 +3090,19 @@ # # The successor to an empty String is a new empty String: # # ''.succ # => "" # - # String#next is an alias for String#succ. - # def succ: () -> String # <!-- # rdoc-file=string.c # - succ! -> self # --> # Equivalent to String#succ, but modifies `self` in place; returns `self`. # - # String#next! is an alias for String#succ!. - # - def succ!: () -> String + def succ!: () -> self # <!-- # rdoc-file=string.c # - sum(n = 16) -> integer # --> @@ -2992,11 +3115,11 @@ # 'тест'.sum # => 1405 # 'こんにちは'.sum # => 2582 # # This is not a particularly strong checksum. # - def sum: (?int n) -> Integer + def sum: (?int bits) -> Integer # <!-- # rdoc-file=string.c # - swapcase(*options) -> string # --> @@ -3115,11 +3238,11 @@ # Returns zero if there is no leading valid number: # # 'abcdef'.to_i # => 0 # '2'.to_i(2) # => 0 # - def to_i: (?int base) -> Integer + def to_i: (?int radix) -> Integer # <!-- # rdoc-file=rational.c # - str.to_r -> rational # --> @@ -3153,21 +3276,17 @@ # - to_s -> self or string # --> # Returns `self` if `self` is a String, or `self` converted to a String if # `self` is a subclass of String. # - # String#to_str is an alias for String#to_s. - # def to_s: () -> String # <!-- rdoc-file=string.c --> # Returns `self` if `self` is a String, or `self` converted to a String if # `self` is a subclass of String. # - # String#to_str is an alias for String#to_s. - # - def to_str: () -> String + alias to_str to_s # <!-- rdoc-file=string.c --> # Returns the Symbol corresponding to *str*, creating the symbol if it did not # previously exist. See Symbol#id2name. # @@ -3180,11 +3299,11 @@ # This can also be used to create symbols that cannot be represented using the # `:xxx` notation. # # 'cat and dog'.to_sym #=> :"cat and dog" # - def to_sym: () -> Symbol + alias to_sym intern # <!-- # rdoc-file=string.c # - tr(selector, replacements) -> new_string # --> @@ -3220,20 +3339,20 @@ # # Escapes. # 'hel^lo'.tr('\^aeiou', '-') # => "h-l-l-" # Escaped leading caret. # 'i-b-m'.tr('b\-z', 'a-z') # => "ibabm" # Escaped embedded hyphen. # 'foo\\bar'.tr('ab\\', 'XYZ') # => "fooZYXr" # Escaped backslash. # - def tr: (string from_str, string to_str) -> String + def tr: (selector source, string relpacement) -> String # <!-- # rdoc-file=string.c # - tr!(selector, replacements) -> self or nil # --> # Like String#tr, but modifies `self` in place. Returns `self` if any changes # were made, `nil` otherwise. # - def tr!: (string from_str, string to_str) -> String? + def tr!: (selector source, string relpacement) -> self? # <!-- # rdoc-file=string.c # - tr_s(selector, replacements) -> string # --> @@ -3244,22 +3363,22 @@ # 'hello'.tr_s('el', '-') #=> "h-o" # 'hello'.tr_s('el', 'hx') #=> "hhxo" # # Related: String#squeeze. # - def tr_s: (string from_str, string to_str) -> String + def tr_s: (selector source, string replacement) -> String # <!-- # rdoc-file=string.c # - tr_s!(selector, replacements) -> self or nil # --> # Like String#tr_s, but modifies `self` in place. Returns `self` if any changes # were made, `nil` otherwise. # # Related: String#squeeze!. # - def tr_s!: (string from_str, string to_str) -> String? + def tr_s!: (selector source, string replacement) -> self? # <!-- # rdoc-file=string.c # - undump -> string # --> @@ -3307,22 +3426,22 @@ # "a\u0300".unicode_normalize # => "a" # "\u00E0".unicode_normalize(:nfd) # => "a " # # Related: String#unicode_normalize!, String#unicode_normalized?. # - def unicode_normalize: (?:nfc | :nfd | :nfkc | :nfkd) -> String + def unicode_normalize: (?:nfc | :nfd | :nfkc | :nfkd form) -> self # <!-- # rdoc-file=string.c # - unicode_normalize!(form = :nfc) -> self # --> # Like String#unicode_normalize, except that the normalization is performed on # `self`. # # Related String#unicode_normalized?. # - def unicode_normalize!: (?:nfc | :nfd | :nfkc | :nfkd) -> String + def unicode_normalize!: (?:nfc | :nfd | :nfkc | :nfkd form) -> self # <!-- # rdoc-file=string.c # - unicode_normalized?(form = :nfc) -> true or false # --> @@ -3351,20 +3470,21 @@ # - unpack(template, offset: 0) -> array # --> # Extracts data from `self`, forming objects that become the elements of a new # array; returns that array. See [Packed Data](rdoc-ref:packed_data.rdoc). # - def unpack: (String format, ?offset: Integer) -> Array[Integer | Float | String | nil] + def unpack: (string template, ?offset: int) -> Array[Integer | Float | String | nil] + | (string template, ?offset: int) { (Integer | Float | String | nil value) -> void } -> nil # <!-- # rdoc-file=pack.rb # - unpack1(template, offset: 0) -> object # --> # Like String#unpack, but unpacks and returns only the first extracted object. # See [Packed Data](rdoc-ref:packed_data.rdoc). # - def unpack1: (String format) -> (Integer | Float | String | nil) + def unpack1: (string template, ?offset: int) -> (Integer | Float | String)? # <!-- # rdoc-file=string.c # - upcase(*options) -> string # --> @@ -3437,12 +3557,12 @@ # # With no block given, returns a new Enumerator: # # 'a8'.upto('b6') # => #<Enumerator: "a8":upto("b6")> # - def upto: (string other_str, ?boolish exclusive) -> Enumerator[String, self] - | (string other_str, ?boolish exclusive) { (String s) -> void } -> self + def upto: (string other_string, ?boolish exclusive) -> Enumerator[String, self] + | (string other_string, ?boolish exclusive) { (String s) -> void } -> self # <!-- # rdoc-file=string.c # - valid_encoding? -> true or false # --> @@ -3451,81 +3571,14 @@ # "\xc2\xa1".force_encoding("UTF-8").valid_encoding? # => true # "\xc2".force_encoding("UTF-8").valid_encoding? # => false # "\x80".force_encoding("UTF-8").valid_encoding? # => false # def valid_encoding?: () -> bool - - private - - # <!-- - # rdoc-file=string.c - # - String.new(string = '', **opts) -> new_string - # --> - # Returns a new String that is a copy of `string`. - # - # With no arguments, returns the empty string with the Encoding `ASCII-8BIT`: - # - # s = String.new - # s # => "" - # s.encoding # => #<Encoding:ASCII-8BIT> - # - # With optional argument `string` and no keyword arguments, returns a copy of - # `string` with the same encoding: - # - # String.new('foo') # => "foo" - # String.new('тест') # => "тест" - # String.new('こんにちは') # => "こんにちは" - # - # (Unlike String.new, a [string - # literal](rdoc-ref:syntax/literals.rdoc@String+Literals) like `''` or a [here - # document literal](rdoc-ref:syntax/literals.rdoc@Here+Document+Literals) always - # has [script encoding](rdoc-ref:encodings.rdoc@Script+Encoding).) - # - # With optional keyword argument `encoding`, returns a copy of `string` with the - # specified encoding; the `encoding` may be an Encoding object, an encoding - # name, or an encoding name alias: - # - # String.new('foo', encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII> - # String.new('foo', encoding: 'US-ASCII').encoding # => #<Encoding:US-ASCII> - # String.new('foo', encoding: 'ASCII').encoding # => #<Encoding:US-ASCII> - # - # The given encoding need not be valid for the string's content, and that - # validity is not checked: - # - # s = String.new('こんにちは', encoding: 'ascii') - # s.valid_encoding? # => false - # - # But the given `encoding` itself is checked: - # - # String.new('foo', encoding: 'bar') # Raises ArgumentError. - # - # With optional keyword argument `capacity`, returns a copy of `string` (or an - # empty string, if `string` is not given); the given `capacity` is advisory - # only, and may or may not set the size of the internal buffer, which may in - # turn affect performance: - # - # String.new(capacity: 1) - # String.new('foo', capacity: 4096) - # - # The `string`, `encoding`, and `capacity` arguments may all be used together: - # - # String.new('hello', encoding: 'UTF-8', capacity: 25) - # - def initialize: (?string str, ?encoding: encoding, ?capacity: int) -> void - - # <!-- - # rdoc-file=string.c - # - replace(other_string) -> self - # --> - # Replaces the contents of `self` with the contents of `other_string`: - # - # s = 'foo' # => "foo" - # s.replace('bar') # => "bar" - # - alias initialize_copy replace end +%a{steep:deprecated} interface _ArefFromStringToString def []: (String) -> String end +%a{steep:deprecated} type String::encode_fallback = Hash[String, String] | Proc | Method | _ArefFromStringToString