# Outputting a txt file

**URL:** <https://www.ruby-forum.com/t/outputting-a-txt-file/130632>\
**Category:** Ruby\
**Created:** [March 1, 2008, 12:51am UTC](https://www.ruby-forum.com/t/outputting-a-txt-file/130632 "2008-03-01T00:51:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 1, 2008, 12:51am UTC](https://www.ruby-forum.com/t/outputting-a-txt-file/130632/1 "2008-03-01T00:51:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 1, 2008, 1:00am UTC](https://www.ruby-forum.com/t/outputting-a-txt-file/130632/2 "2008-03-01T01:00:07Z")

</div>

Hi,

How about create\_log.write “sync Log for #{Time.now}” instead? Try it.  
🙂

Arlen

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 1, 2008, 1:01am UTC](https://www.ruby-forum.com/t/outputting-a-txt-file/130632/3 "2008-03-01T01:01:36Z")

</div>

Thanks, that worked!

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 1, 2008, 2:44am UTC](https://www.ruby-forum.com/t/outputting-a-txt-file/130632/4 "2008-03-01T02:44:40Z")

</div>

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().
