On 03 Dec 2004, at 15:36, John Sands wrote:

> I'm packing up a file into an e-mail attachment using base64 encoding
> and I'm only getting the first line of the file. I've discovered that
> it's a misunderstanding I have about the pack method:
>
> irb(main):001:0> ["a", "b", "c"].pack("m").unpack("m")
> => ["a"]
>
> How do I get the whole array packed?

The Array in Array#pack is like a C struct, and the argument to pack is 
the format string to pack the Array into, so ["a", "b", "c"].pack "m" 
only packs one of the strings you provided.

You certainly don't want to pack the strings individually (["a", "b", 
"c"].pack "mmm"), instead you simply need to join the Array before 
packing:

body = ["a", "b", "c"].join("\n")

[body].pack("m")