From: James Britt Date: 2006-08-05T14:01:09+09:00 Subject: Re: Simple Reading, Deleting and Writing to Files Skeets wrote: > > what i don't know how to do is to... > > 1. write this data to a newly created file (case: file doesn't exist) File.open( some_file_name, 'w'){|f| f.puts(the_data)} > 2. overwrite the data (case: file exists but data needs to be updated). You can use the same code. It will overwrite the current file with the new data. > > eg, let's say my ip changed to 127.0.0.2. i want to delete "#ip > 127.0.0.1" and replace it with "#ip 127.0.0.2". i i'd also consider if > deleting just 127.0.0.1 and replacing it with 127.0.0.2 if it makes > more sense. Just overwrite the old file with the new, complete, data. > > can anyone point me to a tutorial or lend a hand? > Look at http://www.ruby-doc.org/core/classes/IO.html and http://www.ruby-doc.org/core/classes/File.html Note that the File class inherits from IO, so behavior of interest may be defined in either place. -- James Britt http://www.ruby-doc.org - Ruby Help & Documentation http://www.artima.com/rubycs/ - The Journal By & For Rubyists http://www.rubystuff.com - The Ruby Store for Ruby Stuff http://www.jamesbritt.com - Playing with Better Toys http://www.30secondrule.com - Building Better Tools