From: Ken Bloom Date: 2006-10-19T10:15:06+09:00 Subject: Re: whats this lambda code doing? On Thu, 19 Oct 2006 10:02:11 +0900, David Vallner wrote: > Ezra Zygmuntowicz wrote: >> klasses.inject(block) do |blk, klass| >> lambda { klass.with_scope(scope_hash, &blk) } >> end.call >> >> That outer block that ends on end returns the lambda made inside of that >> block. So end.call ends up being lambda { klass.with_scope(scope_hash, >> &blk) }.call >> > > Hmm. Unless I'm very mistaken, it would also only call the lambda for > the last object in klasses, generating several garbage (and relatively > expensive) lambdas. Boggle. Am I missing something? > > David Vallner This some wierd kind of lambda chaining. You're confusing "block" with "blk", so you're thinking that each version of this code is using the original block, but this is not so. Each lambda is chained to call the previous lambda. I haven't got a clue what with_scope does, but this would all be a lot easier to understand if it was possible to eliminate the lambda, and deal with each class separately. -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/ I've added a signing subkey to my GPG key. Please update your keyring.