From: Bill Clagett Date: 2004-03-19T04:20:34+09:00 Subject: Re: Can I stop each's iteration, and get the results so far? On Fri, Mar 19, 2004 at 03:21:16AM +0900, Sam Roberts wrote: > Basically, I want to break from a find_all, and get the array of > elements found so far. Is this possible? > ... I can't think of a way to use 'break' here. But you could use throw and catch. my_enumerable = (1..1000) my_enumerable.instance_eval do @old_each = self.method(:each) def each catch :stop_each do @old_each.call {|n| yield n} end end end my_enumerable.collect do |n| throw :stop_each if n > 20 "n is #{n}" end #bill