Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Hash#values and Hash#keys order

Reply
Thread Tools

Hash#values and Hash#keys order

 
 
Alex Fenton
Guest
Posts: n/a
 
      04-07-2006
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?

thanks
alex
 
Reply With Quote
 
 
 
 
George Ogata
Guest
Posts: n/a
 
      04-15-2006
Alex Fenton <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If you get an order # does it mean the order is accepted? =?Utf-8?B?U3RldmUxMDc3?= Windows 64bit 3 05-12-2005 11:46 PM
DVD Verdict reviews: LAW AND ORDER: SPECIAL VICTIMS UNIT: THE FIFTH YEAR and more! DVD Verdict DVD Video 0 11-03-2004 10:12 AM
Traversion order cf. output order in XSL Soren Kuula XML 2 02-01-2004 09:10 AM
In which order are files looked for when loaded/requierd - and what'sthe order of suffixes? Stephan Kämper Ruby 2 01-18-2004 02:07 PM
How to Display DropDownList with preserved order (custom order) cspoh ASP .Net Web Controls 0 07-31-2003 09:19 AM



Advertisments