Computer Science Canada

File IO?

Author:  Mackie [ Tue Apr 08, 2008 3:53 pm ]
Post subject:  File IO?

How do you read/write/make new files in Ruby? I have an idea i must know!

Author:  Tony [ Tue Apr 08, 2008 4:17 pm ]
Post subject:  RE:File IO?

Look into the File class.
Ruby:

contents = File::open("myfile.txt", "r").read

Author:  haskell [ Wed Apr 09, 2008 5:09 am ]
Post subject:  Re: File IO?

Ruby:

File.open("enter_file_name", "r+") do |file|
  file.puts("This goes in the file!")
  file.puts("This also goes to the file!")
  lines = file.read  # Enitre file added to lines

  lines.each_line do |l|
    puts l[7] + '  ' +  l[4] + '  ' # Print the 5th and 8th character of each line 
  end
end


: