On Jul 17, 2006, at 7:31 PM, Xavier Hanin wrote:

> Logan Capaldo wrote:
>>
>> The ! (pronounced bang usually) means that a method is a "dangerous"
>> version of a method with the same name. In this particular case it
>> means that it's the inplace version of gsub (global substitution).
>
> OK, thanks for the information and the pronounciation tip.
>
> But I still don't know how to edit a file while reading it. I've made
> further googling on the subject, and the only solutions I find are:
> - "read all, manipulate, write all", which doesn't seem very good with
> huge files
> - use -i options with ruby command line, but this seems to work only
> with files passed on the command line, which isn't my case.
>
> So, could somebody tell me if it's possible to update a file in ruby
> (except these two solutions)?

do you want something like this?

cg5:~ >cat a
abcdefghijklm
cg5:~ >cat a.rb
f = File.new("a", "r+")
while f.read(1) !~ /d/
end
f.write("ZZZ")
cg5:~ >ruby a.rb
cg5:~ >cat a
abcdZZZhijklm
cg5:~ >


-- Elliot Temple
http://www.curi.us/blog/