Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Outputting a txt file
Jeff Miller
2/29/2008 11:51:00 PM
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-...
.
3 Answers
Arlen Cuss
2/29/2008 11:59:00 PM
0
[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
Jeff Miller
3/1/2008 12:02:00 AM
0
Thanks, that worked!
--
Posted via
http://www.ruby-...
.
7stud --
3/1/2008 1:45:00 AM
0
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-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Outputting a txt file
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password