[LRUG] Newbie-advice for Rio?

Tom Armitage tom at infovore.org
Fri Mar 17 02:34:06 PST 2006

So I've been hunting through Google for some advice on this and had no avail,
and I'm sure somebody here must have used Rio.

In a nutshell: I'm trying to iterate through a directory called "dummy" and all
subdirectories, replacing instances of the string "#foo#" with "bar". Writing
this in Ruby, it seemed that Rio was the best way to go.

So far, I've got this :

rio('dummy').all.files.skip(/^\./).do |eachfile|
  # blah

which works OK - iterates through all files in directory and recursively through
subdirectories, and leaves out the dot-files like .DS_Store.


However, I'm having no luck getting gsub to work on eachfile. What's the next
part of the operation? What am I doing wrong?

I tried (in place of "# blah~ above)

eachfile < eachfile.gsub('#foo#', 'bar')

but that essentially just emptied each file in turn. Do I need to be creating
copies of each file and deleting the original, or have I missed a trick?

Also, I tried appending the altered file to the end of the original (using << )
and found it didn't perform any gsub - which is also weird. Any idea what might
be calling that?

Apologies if this isn't appropriate for the list, but I thought it'd be easier
to turn here than to ruby-talk or comp.lang.ruby

Also, apologies if it's really bloody obvious. But any help would be greatly


More information about the Chat mailing list