"Robert Klemme" <bob.news / gmx.net> wrote in message news:<2l58ksF8qv8pU1 / uni-berlin.de>... > > A check for block_given? is missing here: > No, I don't think so. arbitrate will be empty if there is no block > > class Hash > > def invert_test(&b) > reverse = self.class.new > > each do |key, val| > if b and reverse.has_key? val > b.call reverse, val, key > else > reverse[val] = key > end > end > > reverse > end > > end The trouble with this approach is that you get called on each duplicate value. Sometimes I find I can only decide on the most appropriate candidate if I've seen them all, but in most cases your implementation would work as well. Cheers, Han Holl