From: Michael campbell Date: 2004-02-01T10:05:27+09:00 Subject: Re: Save the flip/flop op! Phil Tomson wrote: > In article <6e869a6b.0401311614.1334a5fc@posting.google.com>, > Avi Bryant wrote: > >>I wrote: >> >> def from(start_cond, end_cond) >> @in_range = true if start_cond >> yield >> @in_range = false if end_cond >> end >> >>Ack. That should be "yield if @in_range", of course. > > > > Seems to work and be nestable, as in the usage here: > > ff = FlipFlop.new > ff2= FlipFlop.new > f = File.open('filename') > f.each_line {|l| > ff.from(l=~/BEGIN/, l=~/END/) do > #inside the BEGIN .. END block > ff2.from(l=~/def/,l=~/end/) do > #inside def .. end block > puts l > end > end > } > > But it's more cumbersome having to predeclare all the FlipFlops. No doubt. I haven't had a chance to try it yet, but do either Avi's or Nathaniel's solutions work in the "do_something if something..something_else" form?