From: avi@...4.com (Avi Bryant) Date: 2004-02-01T09:09:53+09:00 Subject: Re: Save the flip/flop op! ptkwt@aracnet.com (Phil Tomson) wrote in message news:... > And just what would you replace that functionality with? It seems to me > that it would take several lines of code to replace the following > functionality: > > f.each_line {|l| > if l=~/BEGIN/ .. l=~/END/ > #do something in this range of lines > end > } What an odd operator! It took me a bit of toying around to figure out exactly what it does (I didn't know what the scope of its state variable was, but evidently it's the enclosing method). Anyway, it seems to me you could pretty easily replace this with a simple flipflop class: ff = FlipFlop.new f.each_line {|l| ff.from(l=~/BEGIN/, l=~/END/) do #do something in this range of lines end } class FlipFlop def initialize @in_range = false end def from(start_cond, end_cond) @in_range = true if start_cond yield @in_range = false if end_cond end end Seems a lot clearer than a special operator. But maybe that's just my Smalltalker's minimalism coming out... Avi