From: Anders Borch Date: 2003-07-17T20:15:23+09:00 Subject: Re: Keyword "with" Anders Borch wrote: > Brian Candler wrote: > >> On Thu, Jul 17, 2003 at 06:54:44PM +0900, Anders Borch wrote: >> >>> Now, any file loaded with loadpp may contain the ++ operator, and it >>> will be replaced with '+= 1'. Have fun with it if you like :) >> >> >> >> It might be better to replace foo++ with (foo=foo.succ) because it >> will work >> on things other than numbers - except for some reason there doesn't >> seem to >> be any 'pred', so you can't implement foo-- in this way :-( >> >> irb(main):003:0> "fred".succ >> => "free" >> > > true... I wouldn't be able to implement that in as few lines, since > #succ does not modify the receiver the way +=1 and ++ does. > actually I was wrong... gsub solves this quite nicely... def loadpp(l) s = '' f = File.new(l,'r') f.each_line do |line| s += line.gsub(/(\w)\+\+)/,'\1=\1.succ') + "\n" end eval(s) end /Anders