On Thu, Oct 20, 2011 at 12:43 AM, Yossef Mendelssohn <ymendel / pobox.com> wr=
ote:
> On Oct 19, 4:47=A0pm, Jes=FAs Gabriel y Gal=E1n <jgabrielyga... / gmail.com=
>
> wrote:
>> A way to get a hash that contains a key for each letter with an array
>> of words starting with that letter:
>>
>> h =3D {}
>> names.each do |name|
>> =A0 letter =3D name[0,1].upcase #seems the letters must be upcased
>> =A0 (h[letter] ||=3D []) << name
>> end
>
> This is a good place to use Enumerable#group_by.
>
> =A0 =A0>> names =3D %w(simon sadie tyler kirsty kevin keith)
> =A0 =A0=3D> ["simon", "sadie", "tyler", "kirsty", "kevin", "keith"]
> =A0 =A0>> names.group_by { |n| n[0,1].upcase }
> =A0 =A0=3D> {"K"=3D>["kirsty", "kevin", "keith"], "S"=3D>["simon", "sadie=
"],
> "T"=3D>["tyler"]}

Quite true !
Thanks for the reminder.

Jesus.