Tempfile document updated.
[ruby.git] / pack.rb
blobb6e29c3eab4f1244d7e2120559c39f4f10aab0ec
1 class Array
2   #  call-seq:
3   #    pack(template, buffer: nil) -> string
4   #
5   #  Formats each element in +self+ into a binary string; returns that string.
6   #  See {Packed Data}[rdoc-ref:packed_data.rdoc].
7   def pack(fmt, buffer: nil)
8     Primitive.pack_pack(fmt, buffer)
9   end
10 end
12 class String
13   # call-seq:
14   #   unpack(template, offset: 0) -> array
15   #
16   #  Extracts data from +self+, forming objects that become the elements of a new array;
17   #  returns that array.
18   #  See {Packed Data}[rdoc-ref:packed_data.rdoc].
19   def unpack(fmt, offset: 0)
20     Primitive.attr! :use_block
21     Primitive.pack_unpack(fmt, offset)
22   end
24   # call-seq:
25   #   unpack1(template, offset: 0) -> object
26   #
27   #  Like String#unpack, but unpacks and returns only the first extracted object.
28   #  See {Packed Data}[rdoc-ref:packed_data.rdoc].
29   def unpack1(fmt, offset: 0)
30     Primitive.pack_unpack1(fmt, offset)
31   end
32 end