* Robert Klemme <shortcutter / googlemail.com> (2009-10-31) schrieb:

> On 10/31/2009 10:02 AM, Simon Krahnke wrote:
>> * Robert Klemme <shortcutter / googlemail.com> (2009-10-27) schrieb:
>>
>> Just to play around with ruby 1.9:
>>
>>> DAYS = %w{Sun Mon Tue} # ...
>>
>> You can construct the hash doing the opposite translation with:
>>
>> DAYS_TO_I = DAYS.each_with_index.inject({}) { | h, (v, i) | h[v] = i; h }.freeze
>>
>> Any more simple way to do that?
>
> Not that I'm aware of.  With a Hash you could use #invert but that is
> not available for Array it seems.

There's Hash#invert? Never saw that before, thank you.

As usual, the Pickaxe is more descriptive than rdoc, the first mentions
that if multiple keys map to the same value, only one of the keys
survives the inversion.

mfg,                       simon .... l