From: Bertram Scharpf Date: 2009-10-26T21:40:44+09:00 Subject: Re: Array Number of Leaves Hi, Am Montag, 26. Okt 2009, 21:17:17 +0900 schrieb Robert Klemme: > 2009/10/26 salai : > >    self.inject(0){|acc,x| > >        if x.kind_of?(Array) > >          acc += x.number_of_leaves > >        else > >          acc += x > > The line above should read acc += 1. You could even simplify that as > > acc += (x.number_of_leaves rescue 1) > > >        end > >      } I prefer doing it with `case'. I admit I did no performance check. inject( 0) { |acc,x| acc += case x when Array then x.number_of_leaves else 1 end } Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de