From: Thomas Hafner Date: 2007-01-29T20:55:05+09:00 Subject: Re: cartesian product of arrays "karoyakani" wrote/schrieb <1170049485.669713.169350@h3g2000cwc.googlegroups.com>: > def cartprod(*args) > args.shift.cartprod(args) ^^^^ args.shift.cartprod(*args) with the additional ``*'' would be better ... > end > > Then both forms work as below: > p (1..2).cartprod((3..5), (6..8)) > p cartprod([1,2],[3,4,5],[6,7,8]) ... otherwise the second statement produces different output. Very nice! > Further consideration would be to use a block for output formating: > e.g. replace result << [n] + a above to yield n, a and a block {|n,a| n > +a.join(' ')} for string concatination etc Great, still more abstraction! Regards Thomas