Pit Capitain
3/28/2006 12:31:00 PM
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