Tammo Freese <tammo.freese / offis.de> 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