[DOC] Tweaks for String#<< (#13306)
This commit is contained in:
parent
10e8119cff
commit
7afee53fa0
Notes:
git
2025-05-14 19:24:43 +00:00
Merged-By: peterzhu2118 <peter@peterzhu.ca>
33
string.c
33
string.c
@ -4308,22 +4308,34 @@ rb_str_append_as_bytes(int argc, VALUE *argv, VALUE str)
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* string << object -> string
|
||||
* self << object -> self
|
||||
*
|
||||
* Concatenates +object+ to +self+ and returns +self+:
|
||||
* Appends a string representation of +object+ to +self+;
|
||||
* returns +self+.
|
||||
*
|
||||
* If +object+ is a string, appends it to +self+:
|
||||
*
|
||||
* s = 'foo'
|
||||
* s << 'bar' # => "foobar"
|
||||
* s # => "foobar"
|
||||
*
|
||||
* If +object+ is an Integer,
|
||||
* the value is considered a codepoint and converted to a character before concatenation:
|
||||
* If +object+ is an integer,
|
||||
* its value is considered a codepoint;
|
||||
* converts the value to a character before concatenating:
|
||||
*
|
||||
* s = 'foo'
|
||||
* s << 33 # => "foo!"
|
||||
*
|
||||
* If that codepoint is not representable in the encoding of
|
||||
* _string_, RangeError is raised.
|
||||
* Additionally, if the codepoint is in range <tt>0..0xff</tt>
|
||||
* and the encoding of +self+ is Encoding::US_ASCII,
|
||||
* changes the encoding to Encoding::ASCII_8BIT:
|
||||
*
|
||||
* s = 'foo'.encode(Encoding::US_ASCII)
|
||||
* s.encoding # => #<Encoding:US-ASCII>
|
||||
* s << 0xff # => "foo\xFF"
|
||||
* s.encoding # => #<Encoding:BINARY (ASCII-8BIT)>
|
||||
*
|
||||
* Raises RangeError if that codepoint is not representable in the encoding of +self+:
|
||||
*
|
||||
* s = 'foo'
|
||||
* s.encoding # => <Encoding:UTF-8>
|
||||
@ -4331,14 +4343,7 @@ rb_str_append_as_bytes(int argc, VALUE *argv, VALUE str)
|
||||
* s = 'foo'.encode(Encoding::EUC_JP)
|
||||
* s << 0x00800080 # invalid codepoint 0x800080 in EUC-JP (RangeError)
|
||||
*
|
||||
* If the encoding is US-ASCII and the codepoint is 0..0xff, _string_
|
||||
* is automatically promoted to ASCII-8BIT.
|
||||
*
|
||||
* s = 'foo'.encode(Encoding::US_ASCII)
|
||||
* s << 0xff
|
||||
* s.encoding # => #<Encoding:BINARY (ASCII-8BIT)>
|
||||
*
|
||||
* Related: String#concat, which takes multiple arguments.
|
||||
* Related: see {Modifying}[rdoc-ref:String@Modifying].
|
||||
*/
|
||||
VALUE
|
||||
rb_str_concat(VALUE str1, VALUE str2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user