From: "Brian Schröder" Date: 2005-07-28T23:21:29+09:00 Subject: Re: Combination of two arrays On 28/07/05, Jim Freeze wrote: > * Ara.T.Howard [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/