What if you put a number in the array?

Sent from my phone

> On Nov 20, 2014, at 12:09 AM, Robert Klemme <shortcutter / googlemail.com> w=
rote:
>=20
>> On Thu, Nov 20, 2014 at 8:41 AM, Augusts Bautra <augusts / creo.mobi> wrote=
:
>>=20
>> As I started.. use Inject
>>=20
>> def sum (*numbers)
>>   numbers.inject {|sum, n| sum + n }
>> end
>>=20
>> Inject initialises an empty (zero) receptacle for aggregated data for you=
.
>=20
> No. Your approach is broken because
>=20
> irb(main):001:0> [].inject {|sum, n| sum + n }
> =3D> nil
>=20
>> More at http://blog.jayfields.com/2008/03/ruby-inject.html
>=20
> That has it correct in the first example.  You need to pass in the
> neutral element of the operation:
>=20
> irb(main):002:0> [].inject(0) {|sum, n| sum + n }
> =3D> 0
>=20
> Cheers
>=20
> robert
>=20
> --=20
> [guy, jim].each {|him| remember.him do |as, often| as.you_can - without en=
d}
> http://blog.rubybestpractices.com/