diff options
author | Tanaka Akira <akr@fsij.org> | 2021-10-25 12:25:13 +0900 |
---|---|---|
committer | Tanaka Akira <akr@fsij.org> | 2021-10-25 12:25:13 +0900 |
commit | b74f9d656a028430d942fb609f79c4027f0549fa (patch) | |
tree | 01a2040a8382b55f02d153f8f9f3cb3e41044b61 | |
parent | 66d09501c2476c55664135209e657477a626afb6 (diff) | |
download | ruby-b74f9d656a028430d942fb609f79c4027f0549fa.tar.gz |
add example for buffer: argument of pack.
-rw-r--r-- | pack.rb | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -33,6 +33,16 @@ class Array # the offset, the rest of <i>offsetOfBuffer</i> are overwritten by the result. # If it's shorter, the gap is filled with ``<code>\0</code>''. # + # # packed data is appended by default + # [255].pack("C", buffer:"foo".b) #=> "foo\xFF" + # + # # "@0" (offset 0) specifies that packed data is filled from beginning. + # # Also, original data after packed data is removed. ("oo" is removed.) + # [255].pack("@0C", buffer:"foo".b) #=> "\xFF" + # + # # If the offset is bigger than the original length, \x00 is filled. + # [255].pack("@5C", buffer:"foo".b) #=> "foo\x00\x00\xFF" + # # Note that ``buffer:'' option does not guarantee not to allocate memory # in +pack+. If the capacity of <i>aBufferString</i> is not enough, # +pack+ allocates memory. |