[DOC] Tweaks for String#append_as_bytes

This commit is contained in:
Burdette Lamar 2025-05-16 11:50:55 -05:00 committed by GitHub
parent a188249616
commit cc90adb68d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2025-05-16 16:51:09 +00:00
Merged: https://github.com/ruby/ruby/pull/13352

Merged-By: peterzhu2118 <peter@peterzhu.ca>

View File

@ -4173,25 +4173,27 @@ rb_str_concat_multi(int argc, VALUE *argv, VALUE str)
/* /*
* call-seq: * call-seq:
* append_as_bytes(*objects) -> string * append_as_bytes(*objects) -> self
* *
* Concatenates each object in +objects+ into +self+ without any encoding * Concatenates each object in +objects+ into +self+; returns +self+;
* validation or conversion and returns +self+: * performs no encoding validation or conversion:
* *
* s = 'foo' * s = 'foo'
* s.append_as_bytes(" \xE2\x82") # => "foo \xE2\x82" * s.append_as_bytes(" \xE2\x82") # => "foo \xE2\x82"
* s.valid_encoding? # => false * s.valid_encoding? # => false
* s.append_as_bytes("\xAC 12") * s.append_as_bytes("\xAC 12")
* s.valid_encoding? # => true * s.valid_encoding? # => true
* *
* For each given object +object+ that is an Integer, * When a given object is an integer,
* the value is considered a Byte. If the Integer is bigger * the value is considered an 8-bit byte;
* than one byte, only the lower byte is considered, similar to String#setbyte: * if the integer occupies more than one byte (i.e,. is greater than 255),
* appends only the low-order byte (similar to String#setbyte):
* *
* s = "" * s = ""
* s.append_as_bytes(0, 257) # => "\u0000\u0001" * s.append_as_bytes(0, 257) # => "\u0000\u0001"
* s.bytesize # => 2
* *
* Related: String#<<, String#concat, which do an encoding aware concatenation. * Related: see {Modifying}[rdoc-ref:String@Modifying].
*/ */
VALUE VALUE