@@ -4308,37 +4308,42 @@ rb_str_append_as_bytes(int argc, VALUE *argv, VALUE str)
43084308
43094309/*
43104310 * call-seq:
4311- * string << object -> string
4311+ * self << object -> self
43124312 *
4313- * Concatenates +object+ to +self+ and returns +self+:
4313+ * Appends a string representation of +object+ to +self+;
4314+ * returns +self+.
4315+ *
4316+ * If +object+ is a string, appends it to +self+:
43144317 *
43154318 * s = 'foo'
43164319 * s << 'bar' # => "foobar"
43174320 * s # => "foobar"
43184321 *
4319- * If +object+ is an Integer,
4320- * the value is considered a codepoint and converted to a character before concatenation:
4322+ * If +object+ is an integer,
4323+ * its value is considered a codepoint;
4324+ * converts the value to a character before concatenating:
43214325 *
43224326 * s = 'foo'
43234327 * s << 33 # => "foo!"
43244328 *
4325- * If that codepoint is not representable in the encoding of
4326- * _string_, RangeError is raised.
4329+ * Additionally, if the codepoint is in range <tt>0..0xff</tt>
4330+ * and the encoding of +self+ is Encoding::US_ASCII,
4331+ * changes the encoding to Encoding::ASCII_8BIT:
4332+ *
4333+ * s = 'foo'.encode(Encoding::US_ASCII)
4334+ * s.encoding # => #<Encoding:US-ASCII>
4335+ * s << 0xff # => "foo\xFF"
4336+ * s.encoding # => #<Encoding:BINARY (ASCII-8BIT)>
4337+ *
4338+ * Raises RangeError if that codepoint is not representable in the encoding of +self+:
43274339 *
43284340 * s = 'foo'
43294341 * s.encoding # => <Encoding:UTF-8>
43304342 * s << 0x00110000 # 1114112 out of char range (RangeError)
43314343 * s = 'foo'.encode(Encoding::EUC_JP)
43324344 * s << 0x00800080 # invalid codepoint 0x800080 in EUC-JP (RangeError)
43334345 *
4334- * If the encoding is US-ASCII and the codepoint is 0..0xff, _string_
4335- * is automatically promoted to ASCII-8BIT.
4336- *
4337- * s = 'foo'.encode(Encoding::US_ASCII)
4338- * s << 0xff
4339- * s.encoding # => #<Encoding:BINARY (ASCII-8BIT)>
4340- *
4341- * Related: String#concat, which takes multiple arguments.
4346+ * Related: see {Modifying}[rdoc-ref:String@Modifying].
43424347 */
43434348VALUE
43444349rb_str_concat (VALUE str1 , VALUE str2 )
0 commit comments