From: Gavin Sinclair Date: 2003-11-20T23:45:36+09:00 Subject: Re: learning the "Ruby way" On Thursday, November 20, 2003, 8:07:14 PM, Mark wrote: > [...] > Problem: > I have a sorted list ('alfred', 'boris', 'bruce', 'claire', 'dean', 'donald') > and would like to generate or return ('-a-', 'alfred', '-b-', 'boris', > 'bruce', '-c-', 'claire', '-d-', 'dean', 'donald'). > Here's my solution: > [...] > Is this the "Ruby way" of solving this problem? I doubt it, defining > "helper variables" like this is what had to be done in Basic, and my > solution doesn't demonstrate the high degree of readability Ruby is often > praised for. > Any useful suggestions for me? I'd be very grateful! > Mark My first thought was to collect the values into a hash { 'a' => ['alfred'], 'd' => ['dean', 'donald'], ... } then render that hash into the array that you want. It's unlikely to be all that efficient, but both steps are very easy. Cheers, Gavin