[LRUG] Newbie-advice for Rio?

Tom Ward tom at popdog.net
Fri Mar 17 03:05:28 PST 2006


rio('dummy').all.files.skip(/^\./).do |eachfile|
  eachfile < eachfile.contents.gsub("something", "something else")
end

Tom

On 3/17/06, Tom Armitage <tom at infovore.org> wrote:
> 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
> end
>
> which works OK - iterates through all files in directory and recursively through
> subdirectories, and leaves out the dot-files like .DS_Store.
>
> Fine.
>
> 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
> appreciated.
>
> t.
>
> _______________________________________________
> chat mailing list
> chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>


More information about the Chat mailing list