From: Robert Klemme Date: 2004-03-05T23:59:43+09:00 Subject: Re: rescue inside block -> syntax error "Joe Mason" schrieb im Newsbeitrag news:slrnc4h1oi.ah6.joe@gate.notcharles.ca... > In article , Robert Klemme wrote: > >> But wouldn't the ruby way be to write this? > > > > No, because that would duplicate cleanup code. > > > >> container.each do |obj| > >> processor.create_in_a_way_that_might_throw do |proc| > > > > I gues you rather mean > > > > ProcessorClass.create_in_a_way_that_might_throw do |proc| > > Right. > > > > >> proc.do_work() > >> proc.do_more_work() > >> ensure > >> proc.cleanup() > > > > The cleanup wrong here because it is done in method > > create_in_a_way_that_might_throw() in this scheme after the yield (see > > File.open() and below). > > Oh, that's an ensure, not an except. I was reading too fast (and I > still find Ruby's exception keywords hard to sort out, since they're so > different from everything else I've used. > > Still, I think my example would be a good way to write a rescue clause > for actions only taken in case of failure, and which would benefit from > being able to put rescue in arbitrary blocks. Yeah, it sounds more reasonable for rescue clauses than ensure clauses. Agreed. Regards robert