ruby-changes:69408
From: Tanaka <ko1@a...>
Date: Mon, 25 Oct 2021 12:25:44 +0900 (JST)
Subject: [ruby-changes:69408] b74f9d656a (master): add example for buffer: argument of pack.
https://git.ruby-lang.org/ruby.git/commit/?id=b74f9d656a From b74f9d656a028430d942fb609f79c4027f0549fa Mon Sep 17 00:00:00 2001 From: Tanaka Akira <akr@f...> Date: Mon, 25 Oct 2021 12:25:13 +0900 Subject: add example for buffer: argument of pack. --- pack.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pack.rb b/pack.rb index 019fa80be47..e4d629e0f22 100644 --- a/pack.rb +++ b/pack.rb @@ -33,6 +33,16 @@ class Array https://github.com/ruby/ruby/blob/trunk/pack.rb#L33 # 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. -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/