From: Hugh Sasse Staff Elec Eng Date: 2001-03-03T03:44:50+09:00 Subject: [ruby-talk:11912] Re: rewrite with Ruby On Sat, 3 Mar 2001, ts wrote: > >>>>> "H" == Hugh Sasse Staff Elec Eng writes: > > H> How would one make it really generic? Ruby has -i as well, so how can one > H> get at it to do: > H> ruby -i.bak -p -e 'gsub(/^#define DEBUG/, "#undef DEBUG/") config.h > H> in an elegant way, within a program? > > First you copy the file, then you write : That was my point -- is there/should there be a way that this is done transparently, like with the -i option? The -i option sorts all this out for you, so the mechanisms exist inside the interpreter to do this 'magic' for you, so it should be possible to get at these mechanisms from within a program, to turn it on and off at will. Of course one can write it all explicitly -- it is described in the manual what is going on, but if the interpreter "knows" how to do this already it seems silly to spell it all out :-). [...] > #!/usr/bin/ruby > require "mmap" > m = Mmap.new("aa", "rw") If you have already created the copy what does this get you? I don't recall mmap.... [...] > > it's really experimental actually and it define only bang methods (gsub() > is not defined) to don't return a string too big. > > it's also slow, well it's best to not modify the file :-) > > > Guy Decoux > Hugh