From: ptkwt@... (Phil Tomson) Date: 2004-02-01T11:09:54+09:00 Subject: Re: Save the flip/flop op! In article <401C50D5.601@yahoo.com>, Michael campbell wrote: >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? I haven't tried Nathaniel's proposed solution, but Avi's solution takes a block (where the action occurs), so I don't think it would work that way. A different method could probably be added to his FlipFLop class that could work that way. Phil