From: James Dinkel Date: 2008-08-19T22:36:38+09:00 Subject: Re: passing a variable from a block back to the method Michael Morin wrote: > > You can also use catch and throw. I think this method is a little > cleaner. > ah, I think I like the catch and throw method. That's pretty close to what I was visualizing in my head. Just one thing though: > class File > > def self.change(filename) > catch(:nochanges) do > # read the file, execute a block, then write the file > File.open(filename, 'r+') do|file| > lines = file.readlines > > # return if not changing anything > return if yield(lines) == false > > file.pos = 0 > file.print lines > file.truncate(file.pos) > end > end > end > end > You left in the "return if yield(lines) == false", was that a typo? I'm guessing it was. -- Posted via http://www.ruby-forum.com/.