From: Robert Klemme Date: 2004-03-05T17:59:49+09:00 Subject: Re: rescue inside block -> syntax error "Gavin Sinclair" schrieb im Newsbeitrag news:71397207684.20040305112546@soyabean.com.au... > On Friday, March 5, 2004, 4:24:41 AM, Kent wrote: > > > >> +1, and IIRC that rcr just felt in some limbo.. What was wrong with it > >> ? > > > For starters, it would start drifting do..end blocks and {..} blocks > > apart, unless you'd allow it in those too. > > > {|this| > > this.will > > ensure > > self.gag > > other_who_like_curly_braces.gag > > } > > But what is the alternative? I mean, how often do you see code like > this? > > meth(arg) { > begin > # ... > rescue > # ... > end > } Rarely enough, true. 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 or def File.open(file, mode="r") io = create_io_and_throw_if_not_found(file) begin yield io ensure io.close() end end In all these cases you don't gain anything by having do..ensure..end. Kind regards robert