From: "Brian Schröder" Date: 2004-12-05T05:20:42+09:00 Subject: Re: Using yield On Sat, 4 Dec 2004 09:32:39 +0900 "Joe Van Dyk" wrote: > 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? > > Joe Yield is just a shortcut for block.call. If I am Lazy, and I don't need to pass the block further I use yield. But I believe that normally using block.call is more explicit and therefore preferable. It may be the case that block.call has a small performance penalty compared with yield because the block needs to get bound to a variable and therefore be turned into an object. Regards, Brian -- Brian Schr�der http://ruby.brian-schroeder.de/quiz/crossword/ (Spoiler)