--------------enig783383C0715435A317AC8FB3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 call to klasses.inject returns a block (a Proc). The .call evaluates the Proc. The code is a bit too clever for its own good. Personally I could go around and slap everyone that chains a method after a code block / closure block, or tags a statement modifier conditional / loop after it, most of the time it's just golfing to hide an unsightly level of control flow nesting. David Vallner --------------enig783383C0715435A317AC8FB3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFNs0wy6MhrS8astoRAoiFAJ4wrd3lgcPAxMzWaMhN2PDmFOIQKACffzTK xx68vIKlZFUFivXxaqFeK4c Op -----END PGP SIGNATURE----- --------------enig783383C0715435A317AC8FB3--