From: Edmond Kachale Date: 2011-02-03T00:52:21+09:00 Subject: Re: Soliciting some help with inject method --20cf305496b14dd1de049b4ea251 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Le 2 f=E9vrier 2011 17:46:42 UTC+2, edmond.kachale < edmond.kachale@baobabhealth.org> a =E9crit : > > > 2011/2/2 Andrew Wagner > >> Here's one simple way to do it: >> >> hash =3D array.inject({}) do |result, array| >> key,val =3D array >> if result[key].nil? >> result[key] =3D [val] >> else >> result[key].push val >> end >> result >> end >> > > Thanks Adam. I just reduced your lines to make it geeky!! :-) > > hash =3D array.inject({}) do |result, (key, value)| > (result[key].nil?) ? (result[key] =3D [value]) : (result[key].push(valu= e)) > result > end > Sorry, I meant Andrew. But I also value you contribution, Adam and Jes=FBs. In fact, I think your methods are faster than the inject's way. --- Edmond Software Developer | Baobab Health Trust (http://www.baobabhealth.org/) | Malawi Cell: +265 999 465 137 | +265 881 234 717* ** An old dog does not hunt because of speed, but his endurance of the heart.* * * --20cf305496b14dd1de049b4ea251--