On Sat, Dec 04, 2004 at 09:32:39AM +0900, Joe Van Dyk scribed: > 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? I use it to pass in an additional filtering routine to a database selection class. The selection thing knows some basic stuff like time, but if you want to filter more precisely, you can pass it a block: db_generator = new thingy(start_time, end_time) { |x| x.attr1 == "frog" && x.attr2 >= 5 } and then in later code you can grab stuff from the generator and it's filtered in the way you specified. -Dave -- work: dga / lcs.mit.edu me: dga / pobox.com MIT Laboratory for Computer Science http://www.angio.net/