@@ -4308,37 +4308,42 @@ rb_str_append_as_bytes(int argc, VALUE *argv, VALUE str)
4308
4308
4309
4309
/*
4310
4310
* call-seq:
4311
- * string << object -> string
4311
+ * self << object -> self
4312
4312
*
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+:
4314
4317
*
4315
4318
* s = 'foo'
4316
4319
* s << 'bar' # => "foobar"
4317
4320
* s # => "foobar"
4318
4321
*
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:
4321
4325
*
4322
4326
* s = 'foo'
4323
4327
* s << 33 # => "foo!"
4324
4328
*
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+:
4327
4339
*
4328
4340
* s = 'foo'
4329
4341
* s.encoding # => <Encoding:UTF-8>
4330
4342
* s << 0x00110000 # 1114112 out of char range (RangeError)
4331
4343
* s = 'foo'.encode(Encoding::EUC_JP)
4332
4344
* s << 0x00800080 # invalid codepoint 0x800080 in EUC-JP (RangeError)
4333
4345
*
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].
4342
4347
*/
4343
4348
VALUE
4344
4349
rb_str_concat (VALUE str1 , VALUE str2 )
0 commit comments