Xavier Hanin <xhanin / yahoo.fr> writes:

> I'm brand new to ruby, and I'm looking for a way to open a file, read 
> its content and modify it. I've seen that I can open a file in read 
> write mode, but I can't figure out how it works. If I want to replace 
> all occurences of 'search' by 'replace', for instance, what do I have to 
> do?

In general, you need to read in the file (usually line by line) and
write out a new copy with the changes you want.  Editing in place is
only possible if the replacement string is exactly the same length as
the original.

> Searching for an answer to this question, I've found scripts using gsub! 
> What is this exclamation mark?

It means it changes the object it operates on, rather than returning a
changed copy.

-Doug