From: Dave Thomas Date: 2001-03-07T18:34:40+09:00 Subject: [ruby-talk:12221] Re: (long) Re: hash.invert loses data if equal values exist - is this the right behaviour? Tammo Freese writes: > Is there any case where inverting a hash that is not one-to-one > makes sense? (You cannot know the result!) # Here's a hash mapping image files to the names # of people they portray photoSubjects = { "a.gif" => "Dave", "b.gif" => "Fred", "c.gif" => "Dave", "d.gif" => "Tammo", .. "zzz.gif" => "Fred" } ..... # I need to display a picture of Dave display(photoSubjects.invert['Dave']) > If not, wouldn't it be more convenient to throw an exception when > someone is trying to invert such a hash? Because if you _do_ throw an exception, you prevent the behavior should it be what someone wants. On the other hand, it someone wants to check for key duplication, it's easy res = hsh.invert raise "Duplicate key" if res.size != hsh.size Dave