Bob Sidebotham wrote: > > I'm a bit puzzled whether there is any semantic difference between the > two code fragments, below: .... > yield i1 .... > fibUpTo(1000) { |f| print f, " " } > VS. > blk.call i1 .... > fibUpTo(1000, proc { |f| print f, " " }) > These seem to be equivalent as far as I can tell. Is the original > example just syntactic sugar for the other version, AFAIK, the second creates an object (of type Proc), something the first version doesn't do. I tend to use the def fibUpTo( max, &blk ) version to remove the need for the caller to know that its an explicit Proc object, unless I need several of them. > or are there > subtle reasons why a yield statement and magic associated block (I'm > not sure what you call that) is necessary? It's a) more elegant, b) probably more efficient and c) the "real" way to do it. Just like the normal ("real") way to call a method is : object.methodname(arguments) but you can also do dynamic tricks with: method = object.method(:methodname) method.call( arguments ) -- <[ Kent Dahl ]>================<[ http://www.stud.ntnu.no/~kentda/ ]> )____(stud.techn.;ind.шл.data)||(softwareDeveloper.at(Trustix))_( /"Opinions expressed are mine and not those of my Employer, "\ ( "the University, my girlfriend, stray cats, banana fruitflies, " ) \"nor the frontal lobe of my left cerebral hemisphere. "/