How to concatenate all the lines into one string

Hi all,

I am new to Ruby. I just wonder how I can concatenate all the lines from
one file and let them become one string.

Thanks,

Li

···

--
Posted via http://www.ruby-forum.com/.

Li Chen wrote:

I am new to Ruby. I just wonder how I can concatenate all the lines from
one file and let them become one string.

File.read("/path/to/file")

David Vallner

How about:

a=File.open("/home/n6tadam/.xsession").read.gsub!('\n', ' ')

I've substituted the newlines for spaces -- but you can do whatever you
want with it.

-- Thomas Adam

···

On Mon, Oct 09, 2006 at 03:36:43AM +0900, Li Chen wrote:

Hi all,
I am new to Ruby. I just wonder how I can concatenate all the lines from
one file and let them become one string.

--
"If I were a witch's hat, sitting on her head like a paraffin stove, I'd
fly away and be a bat." -- Incredible String Band.

Or maybe

File.readlines("xorg.conf").join(' ').gsub!("\n",' ')

···

--
Posted via http://www.ruby-forum.com/.