From: "Sandor Szücs" Date: 2012-09-26T03:17:56+09:00 Subject: Re: inject problem On 9/25/12 4:18 PM, Roelof Wobben wrote: > > Hello, > > One question so I can understand this way well. > > In this context x = 1 or 2 and y is the place in the hash ? irb> array.inject({}){|x,y| puts "x:#{x}, y:#{y}"; x[y] += 1 rescue x[y] = 1; x} x:{}, y:1 x:{1=>1}, y:2 x:{1=>1, 2=>1}, y:1 x:{1=>2, 2=>1}, y:1 => {1=>3, 2=>1} > > Roelof > > >> Date: Tue, 25 Sep 2012 22:04:50 +0900 >> From: peterhickman386@googlemail.com >> Subject: Re: inject problem >> To: ruby-talk@ruby-lang.org >> >> just do: >> >> array = [ 1, 2 , 1 , 1] >> >> p array.inject({}){|x,y| x[y] += 1 rescue x[y] = 1; x} >> > > -- Viele Gr��e Sandor