From: Ken Bloom Date: 2006-10-19T10:00:07+09:00 Subject: Re: whats this lambda code doing? On Thu, 19 Oct 2006 09:48:07 +0900, hemant wrote: > I came across following code in typo's application.rb and I can't > understand the last part, > > > def with_blog_scoped_classes(klasses=[Content, Article, Comment, > Page, Trackback], &block) > default_id = this_blog.id > scope_hash = { :find => { :conditions => "blog_id = #{default_id}"}, > :create => { :blog_id => default_id } } > klasses.inject(block) do |blk, klass| > lambda { klass.with_scope(scope_hash, &blk) } > end.call > end > > Method will be called with a block and will probably add some scope to > the respective methods of ActiveRecord classes. But whats the last > part? > I mean, end.call? The whole do...end thing (and its binding to the inject call) has higher precedence than the method call that follows it. It's equivalent to x=klasses.inject(block) do ... end x.call -- 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.