From: Joe Mason Date: 2004-03-05T19:24:43+09:00 Subject: Re: rescue inside block -> syntax error In article , Robert Klemme wrote: > There's an issue that limits the usability of do..ensure..end: Typically > you do resource allocation *outside* the begin..end because you don't want > the ensure clause to be executed if something during init fails: > > container.each do |obj| > processor = create_processor_in_a_way_that_might_throw() > > begin > processor.do_work() > processor.do_more_work() > ensure > processor.cleanup() > end > end But wouldn't the ruby way be to write this? container.each do |obj| processor.create_in_a_way_that_might_throw do |proc| proc.do_work() proc.do_more_work() ensure proc.cleanup() end end Joe