From: Max Ischenko Date: 2001-03-02T20:40:03+09:00 Subject: [ruby-talk:11892] rewrite with Ruby I have the following Ruby code: def Mutt.afterConfigure system("perl -i -p -e 's/^#define DEBUG/#undef DEBUG/' config.h") system("perl -i -p -e 's/^#define USE_DOTLOCK.*$/#undef USE_DOTLOCK/' config.h") end It's not very efficient, becuase it forks/exec two processes just to change a line in a file. But, it took me less than a minute to write. Now, I want to write a generic function that will make changes to a file, to use it like this: patchFile 'config.h' do |x| x.gsub!("#define DEBUG", "#undef DEBUG") x.gsub!("#define USE_DOTLOCK", "#undef USE_DOTLOCK") end This don't work: def patchFile(fname, &block) IO.foreach(fname) block end What do I do wrong? -- Any technology distinguishable from magic is insufficiently advanced. -- Arthur C. Clarke