From: Emmanuel Touzery Date: 2003-05-26T17:51:07+09:00 Subject: Re: exiting of a block "Robert Klemme" wrote in message news:bashj0$33hl9$3@ID-52924.news.dfncis.de... > > # now find the current program for this > > # channel. > > programsForChannel.find { |program| > > result = false > > if program.time <= showTime > > if program.endTime > > # there is a endtime. > > # are we now before this end? > > if program.endTime > showTime > > result = true > > end > > else > > # program has no registered > > # end. > > result = true > > end > > end > > result > > } > > > > any help appreciated! > > In your case you can use "return" even with older versions of ruby if you > use a method: > > def find > [1, 2, 3].find { |e| > return true if e == 2 > } > > false > end > > Are you aware of the standard methods Enumerable#include?, > Enumerable#find, Enumerable#detect, Enumerable#select, Enumerable#find_all > and Enumerable#grep? These should provide the functionality you need. the code you give returns returns true or false, i want the item that is found; try it. for the code you gave, i would expect a result of 2. but you get true :O( i actually want to use Enumerable#find, as I do, but with a complex condition. the problem is that in my condition i have several places to say "yes, this is the item i want" or "no, it's not the item i want". in a function i would use return, but in that case, that pops me out of the whole function, not only of the block. actually i want exactly what matz suggested, that's only available in 1.8: break . i'll clean up this code when upgrading to 1.8 :O) > Regards > > robert thanks for the suggestion, emmanuel