Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: What is the order of keys/values returned by Hash.keys and Hash.values methods?

Tags:

ruby

key

hash

Is it the same order in which the items were added to the Hash ?

like image 419
Misha Moroshko Avatar asked Mar 06 '11 03:03

Misha Moroshko


1 Answers

The top of the Ruby 1.9.2 documentation for the Hash class declares:

Hashes enumerate their values in the order that the corresponding keys were inserted.

Cursory tests suggest that this does indeed apply to both Hash#keys and Hash#values, although the corresponding documentation for those methods doesn't seem to specify it.

like image 57
Mark Rushakoff Avatar answered Oct 21 '22 18:10

Mark Rushakoff