Hi,

Am Montag, 26. Okt 2009, 21:17:17 +0900 schrieb Robert Klemme:
> 2009/10/26 salai <sayakyi / gmail.com>:
> > =A0 =A0self.inject(0){|acc,x|
> > =A0 =A0 =A0 =A0if x.kind_of?(Array)
> > =A0 =A0 =A0 =A0 =A0acc +=3D x.number_of_leaves
> > =A0 =A0 =A0 =A0else
> > =A0 =A0 =A0 =A0 =A0acc +=3D x
>=20
> The line above should read acc +=3D 1.  You could even simplify that as
>=20
> acc +=3D (x.number_of_leaves rescue 1)
>=20
> > =A0 =A0 =A0 =A0end
> > =A0 =A0 =A0}

I prefer doing it with `case'. I admit I did no performance check.

  inject( 0) { |acc,x|
    acc +=3D case x
      when Array then   x.number_of_leaves
      else              1
    end
  }

Bertram

--=20
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de