Hello --

On Tue, 9 Jan 2001, [iso-8859-1] Aleksi Niemel? wrote:

> After I've learned Hash#index I'd expect I'm able to guess correctly what
> Hash#indexes does. But I'm not.
> 
>   h = {"abc" => 123, "def" => 456}
>   list = h.keys + h.values
>   a = list.collect { |obj| h.index(obj) }
>   b = h.indexes(*list)
>   p list, a, b
>   p a==b
> 
> outputting:
> 
>   ["def", "abc", 456, 123]
>   [nil, nil, "def", "abc"]
>   [456, 123, nil, nil]
>   false
> 
> I'd expect the last line to be true (that is, the a way and the b way to be
> equivalent). Is there something wrong in my expectations?

#indexes, confusingly (I think), gathers values, whereas #index finds a
key.  So #indexes is not really the plural of #index in this
case....  They behave more as if they were called #values_for and
#key_for.


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav