From: Pit Capitain Date: 2006-03-28T21:31:25+09:00 Subject: Re: Noob: The ruby way to multiple Array by multiple? Ryan Davis schrieb: > a = [1, 2, 3] > b = [4, 5] > > (a * b.size).zip(b * a.size).sort > # => [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]] > > ... > > class Array > def x(b) > a = self > (a * b.size).zip(b * a.size) > end > end > > a.x b > => [[1, 4], [2, 5], [3, 6], [1, 4], [2, 5], [3, 6], [1, 4], [2, 5], [3, > 6]] Ryan, this works only if a.size and b.size are relatively prime, as in your first example. The second example shows the error. If you use sort in a different place it should work, though: (a * b.size).sort.zip(b * a.size) Regards, Pit