From: Prasadhnc C Date: 2012-09-25T18:05:51+09:00 Subject: Re: inject problem --e89a8fb1f1a22fb5ae04ca830365 Content-Type: text/plain; charset=ISO-8859-1 try this, count.inject({}){|x,y| x[y] += 1 rescue x[y] = 1; x} On Tue, Sep 25, 2012 at 2:25 PM, Peter Hickman < peterhickman386@googlemail.com> wrote: > Well the simplest error is the count.inject{| ... |} part. The stuff > that goes between the | ... | are variable declarations. For example > this is sum for an array > > array = [1,2,1,1] > array.inject(0){|x, y| x + y} => 5 > > note the variable 'x' and 'y' are between the | ... | and the action > 'x + y' takes place after. inject is expecting two variable to be > declared so that is another error. > > --e89a8fb1f1a22fb5ae04ca830365 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
try this,
count.inject({}){|x,y| x[y] +=3D 1 rescue x[y] =3D= 1; x}

On Tue, Sep 25, 2012 at 2:25= PM, Peter Hickman <peterhickman386@googlemail.com> wrote:
Well the simplest error is the count.inject{| ... |} part.= The stuff
that goes between the | ... | are variable declarations. For example
this is sum for an array

array =3D [1,2,1,1]
array.inject(0){|x, y| x + y} =3D> 5

note the variable 'x' and 'y' are between the | ... | and t= he action
'x + y' takes place after. inject is expecting two variable to be declared so that is another error.


--e89a8fb1f1a22fb5ae04ca830365--