Outputting a txt file

Hello,
Probably a stupid question, but I can’t seem to get this to work. I can
create the file, but when I open it, it is blank…

create_log = File.new(“sync_log_#{@date}.txt”, “a”)
puts “sync Log for #{Time.now}”
create_log.close

Does anybody know why? It should say “sync Log for (the date and time)”
yet I’m not getting anything…

Any help is appreciated!

Thanks,

  • Jeff

Hi,

How about create_log.write “sync Log for #{Time.now}” instead? Try it.
:slight_smile:

Arlen

Thanks, that worked!

Jeff M. wrote:

Hello,
Probably a stupid question, but I can’t seem to get this to work. I can
create the file, but when I open it, it is blank…

create_log = File.new(“sync_log_#{@date}.txt”, “a”)
puts “sync Log for #{Time.now}”
create_log.close

Does anybody know why? It should say “sync Log for (the date and time)”
yet I’m not getting anything…

  1. ‘create_log’ is the type of name you would use for a method. It
    implies action, i.e. ‘creating’ something. You would use something like
    ‘log_file’ for your variable name.

  2. Calling the method puts without anything in front of it, e.g.
    some_file.puts, means that you want to send the output to STDOUT, which
    by default is your terminal. If you want to use puts on a file, you do
    this:

log_file.puts(…)

  1. write() is not equivalent to puts().