On Feb 12, 1:07 am, "Phrogz" <g... / refinery.com> wrote:
> On Feb 11, 4:40 pm, Alex Young <a... / blackkettle.org> wrote:
>
> > # One-level flatten().
> > r=[];quiz.each{|a|r+=[*a]};r
>
> Elegantly small!
When I saw that, I thought that it could definitely be shortened by
using an inject. After all, there'd be no assignments of r, no final
returning of r, no semicolons. But when all was said and done, it
ended up being the same length. Compare:
quiz.inject([]){|r,a|r+[*a]}
r=[];quiz.each{|a|r+=[*a]};r
Oh well....
Eric
----------------
Are you interested in on-site Ruby training that uses well-designed,
real-world, hands-on exercises? http://LearnRuby.com