"Han Holl" <han.holl / pobox.com> schrieb im Newsbeitrag news:b93fa83f.0407090214.b23e8c5 / posting.google.com... > "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 Oops, yes you're right. > > 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. Well, in that case you can remember them all and act on them later. The advantage of my implementation is that you have to pay the overhead of the second hash only if you really need it. Regards robert