Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Outputting a txt file

Reply
Thread Tools

Outputting a txt file

 
 
Jeff Miller
Guest
Posts: n/a
 
      02-29-2008
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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Arlen Cuss
Guest
Posts: n/a
 
      02-29-2008
[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

 
Reply With Quote
 
 
 
 
Jeff Miller
Guest
Posts: n/a
 
      03-01-2008
Thanks, that worked!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
7stud --
Guest
Posts: n/a
 
      03-01-2008
Jeff Miller 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(...)

3) write() is not equivalent to puts().
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
counting how often the same word appears in a txt file...But my codeonly prints the last line entry in the txt file dgcosgrave@gmail.com Python 8 12-19-2012 06:29 PM
Diff. between FileWriter("f.txt") and OutputStreamWriter(new FileOutputStream("f.txt")) ? Jochen Brenzlinger Java 7 09-15-2011 01:23 AM
Opening a txt file to view ( i.e. readme.txt) Sameen C++ 2 08-29-2005 03:14 PM
problem outputting GIF file when loaded into Bitmap object Stimp ASP .Net 1 10-22-2004 04:34 PM
Outputting text to a file Robert C Programming 3 04-07-2004 05:01 PM



Advertisments