George Ogata
4/15/2006 5:45:00 AM
Alex Fenton <alex@deleteme.pressure.to> writes:
> Hi
>
> Are Hash#keys and Hash#values guaranteed to return the entries in
> the same order? i.e. is the following always true?
>
> hash.values == hash.values_at(*hash.keys )
>
> It seems to work, but can I depend on this behaviour?
In the current implementation, they will always be the same (assuming
the hash isn't modified between the #keys and #values calls). It
isn't documented AFAIK, so I don't know if you can depend on it in the
future. If you don't want to, perhaps you can use:
keys, values = *h.to_a.transpose