From: Dave Thomas Date: 2001-03-07T05:59:40+09:00 Subject: [ruby-talk:12179] Re: (long) Re: hash.invert loses data if equal values exist - is this the right behaviour? gotoken@math.sci.hokudai.ac.jp (GOTO Kentaro) writes: > >Of course this breaks down at "shi" => "four", "yon" => "four", but > >there are many true one-to-one mappings where .invert can be useful. > > Yes, it could be useful sometime. Thank you. > > But I feel a little danger because Hash does not have any checking > mechanism to detect multiple values. At least it should be documented > in the reference manual. To be fair, the example does show it: dave[14:58:19] ri invert ---------------------------------------------------------------------- hsh.invert -> aHash ---------------------------------------------------------------------- Returns a new hash created by using hsh's values as keys, and the keys as values. h = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 } h.invert #=> {200=>"d", 300=>"y", 0=>"a", 100=>"n"} Should we make it more explicit? Dave