From: "Brian Schröder" Date: 2004-11-10T06:51:50+09:00 Subject: Re: Iterating trough hash On Wed, 10 Nov 2004 06:41:08 +0900 Michael DeHaan wrote: > Hmm, that's not a good bug there, so I'll pull the "history" thing out > (I was trying to be too clever)... > > module Enumerable > def each_permutation > each do |item1| > each do |item2| > yield [item1,item2] unless (item1 === item2) > end > end > end > end > > Hello Michael, I think, that this is not each_permutation, but each_ordered_pair_of_elements_in_the_set_except_for_equal_elements. each_permutation would be all shuffles of the original enumerable. And it is not what the OP wanted, as he wanted all unordered pairs. So maybe module Enumerable def each_self_pair each do |item1| each do |item2| yield [item1,item2] end end end end {'me' => 1, 'you' => 1, 'him' => 1}.each_self_pair do | ((p1, a1), (p2, a2) | next if p1 <= p2 puts "#{p1} and #{p2} with age #{a1 + a2}" end would be more appropriate. Regards, Brian > > > [snip] -- Brian Schr�der http://www.brian-schroeder.de/