From: Robert Klemme Date: 2004-12-05T23:37:38+09:00 Subject: Re: Using yield "Joe Van Dyk" schrieb im Newsbeitrag news:I868Ho.73v@news.boeing.com... >I come from a heavy C++ background, discovered Ruby a few months ago and > love it. > > I've found that using blocks is a very natural thing. However, I have not > once used 'yield'. I'm sure that there are events when using yield would > be > helpful, but I have no clue when it would be appropriate to use. > > Thoughts? When do you use the 'yield' statement in code? When implementing Enumerable classes class Endless include Enumerable def each i = 0 loop do yield i i += 1 end end end More generally when you don't need direct access to the block given and when you don't need to forward it to another method call. I think yield is faster than the block form also. Regards robert