Skip to content

Commit 19e2ffb

Browse files
authored
Merge pull request #2935 from kyanagi/string_append_as_bytes
`String#append_as_bytes`を追加
2 parents f4214b8 + a397591 commit 19e2ffb

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

refm/api/src/_builtin/String

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,39 @@ p str # => "foo!!!"
459459
#@end
460460
#@end
461461

462+
#@since 3.4
463+
@see [[m:String#append_as_bytes]]
464+
#@end
465+
466+
#@since 3.4
467+
--- append_as_bytes(*objects) -> self
468+
469+
引数で与えたオブジェクトをバイト列として、self に破壊的に連結します。
470+
471+
このメソッドはエンコーディングの検査や変換を一切行いません。
472+
473+
引数が整数である場合は、その数をバイトの値とみなして連結します。
474+
その数が1バイトの範囲を越える場合は、最下位のバイトのみを使用します。
475+
476+
#@samplecode 例
477+
s = "あ".b # => "\xE3\x81\x82"
478+
s.encoding # => #<Encoding:BINARY (ASCII-8BIT)>
479+
s.append_as_bytes("い") # => "\xE3\x81\x82\xE3\x81\x84"
480+
481+
# s << "い" では連結できない
482+
s << "い" # => "incompatible character encodings: BINARY (ASCII-8BIT) and UTF-8 (Encoding::CompatibilityError)
483+
#@end
484+
485+
#@samplecode 引数で整数を渡す例
486+
t = ""
487+
t.append_as_bytes(0x61) # => "a"
488+
t.append_as_bytes(0x3062) # => "ab"
489+
#@end
490+
491+
@see [[m:String#<<]], [[m:String#concat]]
492+
493+
#@end
494+
462495
--- =~(other) -> Integer | nil
463496

464497
正規表現 other とのマッチを行います。

0 commit comments

Comments
 (0)