Meino Christian Cramer <Meino.Cramer / gmx.de> skrev den Sat, 6 Sep 2003 
16:59:21 +0900:

> Is there a method or ruby-"trick" to solve the problem ?
> Thank you very much in advance for any help and/or hint ! :)
>
There are shorter solutions but here is one pretty clear one:

class Hash
  def invert_with_duplicates
    nh = Hash.new {Array.new}
    self.each {|k,v| nh[v] = (nh[v].push k)}
    nh
  end
end
h = {:a => 1, :b => 1, :c => 2}
p h.invert_with_duplicates # => {1=>[:a, :b], 2=>[:c]}

Regards,

/Robert Feldt