Outputting a txt file

J

Jeff Miller

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
 
A

Arlen Cuss

[Note: parts of this message were removed to make it a legal post.]

Hi,

How about create_log.write "sync Log for #{Time.now}" instead? Try it. :)

Arlen
 
7

7stud --

Jeff said:
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(...)

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top