2.38. Encoding and Decoding Strings (uuencode/uudecode)

The uu in these names means UNIX-to-UNIX. The uuencode and uudecode utilities are a time-honored way of exchanging data in text form (similar to the way base64 is used).

str = "\007\007\002\abdce"

new_string = [str].pack("u")         # '(!P<"!V)D8V4`'
original   =  new_string.unpack("u") # ["\a\a\002\abdce"]

Note that an array is returned by unpack.

Get The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.