From: dblack@... Date: 2007-07-12T01:31:58+09:00 Subject: Re: Catching what a block returns (A newbie lesson learned) Hi -- On Thu, 12 Jul 2007, Richard Lawrence wrote: > Realizing that "yield" evaluates to something I can assign to variables, etc. > was important for getting beyond the trivial examples. In retrospect, I > should have paid more attention to the lesson that *everything* evaluates in > Ruby. I think what I was hung up on is that "yield" is a keyword (right? at > least it looks like one), and hence I thought of it as mere flow control, not > a passage for information. I'm pleased you worked this out, and it does indeed point you to a great deal of yield's coolness. And you're right that keyword expressions, too, always evaluate to something (with the exception of return, since doing this: x = return 1 would at best just discard x). It's true even for class and method definitions: class definition blocks evaluate to the last expression inside them, and def blocks evaluate to nil. So this: class C def m end end evaluates to nil, while this: class C 1 end evaluates to 1. (And yes, this feature does actually get used in slightly more real situations :-) David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)