From: ptkwt@... (Phil Tomson) Date: 2004-02-01T09:54:52+09:00 Subject: Re: Save the flip/flop op! 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. Phil