當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Ruby Buffer.clear用法及代碼示例


本文簡要介紹ruby語言中 IO::Buffer.clear 的用法。

用法

clear(value = 0, [offset, [length]]) → self

value 填充緩衝區,從 offset 開始,然後是 length 字節。

buffer = IO::Buffer.for('test')
# =>
#   <IO::Buffer 0x00007fca40087c38+4 SLICE>
#   0x00000000  74 65 73 74         test

buffer.clear
# =>
#   <IO::Buffer 0x00007fca40087c38+4 SLICE>
#   0x00000000  00 00 00 00         ....

buf.clear(1) # fill with 1
# =>
#   <IO::Buffer 0x00007fca40087c38+4 SLICE>
#   0x00000000  01 01 01 01         ....

buffer.clear(2, 1, 2) # fill with 2, starting from offset 1, for 2 bytes
# =>
#   <IO::Buffer 0x00007fca40087c38+4 SLICE>
#   0x00000000  01 02 02 01         ....

buffer.clear(2, 1) # fill with 2, starting from offset 1
# =>
#   <IO::Buffer 0x00007fca40087c38+4 SLICE>
#   0x00000000  01 02 02 02         ....

相關用法


注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Buffer.clear。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。