From: Joshua Abbott Date: 2008-08-15T13:35:59+09:00 Subject: Re: how exit a block? Have you tried using detect? colors = ['red', 'yellow', 'green', 'blue'] yellow = colors.detect { |color| color == 'yellow' } Detect runs the block on each element until the first that returns true. >> colors = ['red', 'yellow', 'green', 'blue'] => ["red", "yellow", "green", "blue"] >> yellow = colors.detect { |color| color == 'yellow' } => "yellow" -- Josh Greg Willits wrote: > Stefano Crocco wrote: >> On Thursday 14 August 2008, Greg Willits wrote: >>> My actual code is a little different but I am assuming whatever >>> technique solves the above would solve what I need as well. >>> >>> Seems like a simple syntax need, but I'm not finding a conclusive >>> solution. Probably right in front of me, so sorry if it's major >>> obvious... >>> >>> -- gw >> >> break color if color == 'yellow' > > > Oi. yep, break is what I was looking for. I guess I've just never come > across it anywhere (and googling anything ruby with "exit block" turns > up 40 billion exit function discussions). > > Thx > > -- gw -- Posted via http://www.ruby-forum.com/.