Convert multi-line file into single line on the command-line with Ruby rather than awk

On the command-line, how to convert a multi-line file:

cat /tmp/z
aaa
bbb
ccc

Into a single line:

cat /tmp/z | awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}'
aaa\nbbb\nccc\n

...but using ruby rather than awk?

(awk solution obtained here.)

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum