On 28/07/05, Jim Freeze <jim / freeze.org> wrote:
> * Ara.T.Howard <Ara.T.Howard / noaa.gov> [2005-07-28 23:11:32 +0900]:
> 
> >   cross = foo.inject(a=[]){|a,f| bar.inject(a){|a,b| a << [f,b]}}
> 
> Wow, that's great. But my brain hurts.
> 



I like the expanded version better though. Seems somehow less obfuscated.
And the a=[] is superflous:

$ irb
>  foo = [1,2,3]
> bar = %w(a b c)
> foo.inject([]){ |result,a| bar.inject(result){ |result,b| result << [a,b] }}
=> [[1, "a"], [1, "b"], [1, "c"], [2, "a"], [2, "b"], [2, "c"], [3,
"a"], [3, "b"], [3, "c"]]


regards,

Brian


-- 
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/