From: Kirk Haines Date: 2004-02-13T15:08:05+09:00 Subject: Re: return from yielded block On Fri, 13 Feb 2004, Ara.T.Howard wrote: > what i want to do is something like > > value = meth 42 > > where > > def meth n > block_meth do > if n == 42 > return 'forty-two' > else > return 'ask another question' > end > end > end > > def block_meth > yield > end > > > the problem is that you can't 'return' from a block - so how is this done? def block_meth yield end def meth n block_meth do r = nil if n == 42 r = 'forty two' else r = 'ask another question' end r end end irb(main):018:0> x = meth 74 => "ask another question" irb(main):019:0> puts x ask another question => nil irb(main):020:0> y = meth 42 => "forty two" irb(main):021:0> puts y forty two => nil Is that what you are looking for? Kirk Haines