From: "Shot (Piotr Szotkowski)" Date: 2007-12-17T00:03:11+09:00 Subject: Re: An idiomatic way to traverse all pairs in an enumerable? --v9Ux+11Zm5mwPlX6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MonkeeSage: > module Enumerable > def every_pair(other) > self.each { | x | > other.each { | y | > yield [x, y] if x < y > } > } > end > end Ah, perfect. In my (limited) case, it ended up to be module Enumerable def every_pair each_with_index do |a, i| each_with_index do |b, j| yield [a, b] if i < j end end end end >> arr =3D (1..5).sort_by { rand } =3D> [1, 4, 2, 5, 3] >> arr.every_pair { |a, b| p [a, b] } [1, 4] [1, 2] [1, 5] [1, 3] [4, 2] [4, 5] [4, 3] [2, 5] [2, 3] [5, 3] =3D> [1, 4, 2, 5, 3] Most appreciated! -- Shot --=20 XML is like violence, if it doesn't solve your problem you're not using enough of it. --v9Ux+11Zm5mwPlX6 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFHZTM9i/mCfdEo8UoRAkeTAJ9knt7p5OV81MxF9Twpk0UiVdZZeQCcDDgP FG9iRdQDi6ghjHqFa5wZ6NE= =PNx1 -----END PGP SIGNATURE----- --v9Ux+11Zm5mwPlX6--