From: Diego Algorta Casamayou Date: 2006-01-20T01:38:10+09:00 Subject: Re: Unable to write to file... (example from "pickaxe book", second edition, p128) Jacob Fugal escribi�: > On 1/19/06, Diego Algorta Casamayou wrote: >> Change >> >>> File.open("testfile", "r") do |file| >> to >> >>> File.open("testfile", "w") do |file| > > Well you need more than that. For one thing the file.gets will fail if > file was opened in write mode. Also the puts is going to STDOUT, not > the file. You probably want something like this: > > #!/usr/bin/ruby > File.open("testfile", "w") do |file| > while line = gets > file.puts line > end > end > > This will get input from STDIN and write it out to test file. Program > terminates on EOF marker (CTRL-D when run interactively). That's right. I focused my reply on on the open method, but missed the full example. Diego