Writing a file to txt, how can I put a new line?

I would like to create an error log for a application I have made. Here
is my basic error log creator.

My question: How do I get each part of the array on a new line?

  File::open( "Tal Creator Log" + ".txt", "w" ) do |txt|
    txt << "Finished Appending, the new files and a log is located in
P:\\project\\"
    txt << "________________ ISSUES __________________"

    DNErep.reduce { |x| puts txt << x }
    DNEtemp.reduce { |y| puts txt << y }
  end

I looked on google and SO and didn't find anything about the new line.

I appreciate all time spent and look forward to your answers.

···

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

You might want to look at puts. Or maybe one of the logging libraries that
solve logging for you (more or less)

···

On Mon, Apr 30, 2012 at 1:31 PM, Christopher D. <lists@ruby-forum.com>wrote:

I would like to create an error log for a application I have made. Here
is my basic error log creator.

My question: How do I get each part of the array on a new line?

File::open( "Tal Creator Log" + ".txt", "w" ) do |txt|
   txt << "Finished Appending, the new files and a log is located in
P:\\project\\"
   txt << "________________ ISSUES __________________"
   DNErep.reduce { |x| puts txt << x }
   DNEtemp.reduce { |y| puts txt << y }
end

I looked on google and SO and didn't find anything about the new line.

I appreciate all time spent and look forward to your answers.

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

--
thanks,
-pate
-------------------------
Don't judge those who choose to sin differently than you do

pat eyler wrote in post #1058996:

You might want to look at puts. Or maybe one of the logging libraries
that
solve logging for you (more or less)

Hi pat, thanks for getting back to me

The logger isn't exactly what I'm looking for here... just a simple way
to list a few things in my array in a text file line by line instead of
consecutively..

I also tried
txt << puts line
txt << "#{puts ""}"
txt << "#{puts line}"

···

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

pat eyler wrote in post #1058996:
> You might want to look at puts. Or maybe one of the logging libraries
> that
> solve logging for you (more or less)

Hi pat, thanks for getting back to me

The logger isn't exactly what I'm looking for here... just a simple way
to list a few things in my array in a text file line by line instead of
consecutively..

I also tried
txt << puts line
txt << "#{puts ""}"
txt << "#{puts line}"

puts is a method try calling it on your filehandle instead of a default
value. (It returns nil, so the three things you tried above won't do what
you want.)

You probably also learned something else about puts from what those
attempts did.

···

On Mon, Apr 30, 2012 at 1:59 PM, Christopher D. <lists@ruby-forum.com>wrote:

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

--
thanks,
-pate
-------------------------
Don't judge those who choose to sin differently than you do

Have you tried simply writing the whole array joined by carriage returns to the file?

File.open(my_log_file, "w") { |f|
   f.write(my_log_array.join("\n"))
}

Sam

···

On 01/05/12 07:59, Christopher D. wrote:

pat eyler wrote in post #1058996:

You might want to look at puts. Or maybe one of the logging libraries
that
solve logging for you (more or less)

Hi pat, thanks for getting back to me

The logger isn't exactly what I'm looking for here... just a simple way
to list a few things in my array in a text file line by line instead of
consecutively..

I also tried
txt<< puts line
txt<< "#{puts ""}"
txt<< "#{puts line}"

Sam Duncan wrote in post #1059006:

···

On 01/05/12 07:59, Christopher D. wrote:

I also tried
txt<< puts line
txt<< "#{puts ""}"
txt<< "#{puts line}"

Have you tried simply writing the whole array joined by carriage returns
to the file?

File.open(my_log_file, "w") { |f|
   f.write(my_log_array.join("\n"))
}

Sam

Actually just tried that was going to write back with a solution. You
can also append to the array like this:

DNErep.each { |x| txt << "\n#{x}" }

Appreciate the help

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