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.

    >> names =3D %w(simon sadie tyler kirsty kevin keith)
    =3D> ["simon", "sadie", "tyler", "kirsty", "kevin", "keith"]
    >> names.group_by { |n| n[0,1].upcase }
    =3D> {"K"=3D>["kirsty", "kevin", "keith"], "S"=3D>["simon", "sadie"],
"T"=3D>["tyler"]}

--
-yossef