Easiest way is to open a file for writing and with a block write the =
contents to it.

File.open("test_file.txt", "a+") do |file| #opens the file =
"test_file.txt" in append mode, if it does not exist it creates it.
    file.puts "Hello world"
end  #closes the file for you=20

Otherway is to use File.new but that forces you to ensure to close the =
file etc.=20

Regards,
Vicente



On May 2, 2011, at 7:37 PM, Mike Jones wrote:

> Hey guys, can anyone explain how to write to a file in Ruby?
>=20
> Thanks,
>=20
> Mike
>=20
> --=20
> Posted via http://www.ruby-forum.com/.
>=20