Outputting a txt file

Discussion in 'Ruby' started by Jeff Miller, Feb 29, 2008.

  1. Jeff Miller

    Jeff Miller Guest

    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/.
    Jeff Miller, Feb 29, 2008
    #1
    1. Advertising

  2. Jeff Miller

    Arlen Cuss Guest

    [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
    Arlen Cuss, Feb 29, 2008
    #2
    1. Advertising

  3. Jeff Miller

    Jeff Miller Guest

    Jeff Miller, Mar 1, 2008
    #3
  4. Jeff Miller

    7stud -- Guest

    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/.
    7stud --, Mar 1, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stimp
    Replies:
    1
    Views:
    322
    Kevin Spencer
    Oct 22, 2004
  2. Robert

    Outputting text to a file

    Robert, Apr 7, 2004, in forum: C Programming
    Replies:
    3
    Views:
    311
    Dan Pop
    Apr 7, 2004
  3. Sameen
    Replies:
    2
    Views:
    439
    Victor Bazarov
    Aug 29, 2005
  4. Jochen Brenzlinger
    Replies:
    7
    Views:
    5,539
    Roedy Green
    Sep 15, 2011
  5. Jenny Purcell

    Outputting results as html in a file

    Jenny Purcell, Oct 2, 2007, in forum: Ruby
    Replies:
    1
    Views:
    118
    Jesús Gabriel y Galán
    Oct 2, 2007
Loading...

Share This Page