From: Jason Voegele Date: 2001-12-12T00:28:48+09:00 Subject: [ruby-talk:28230] Re: Hash.keys Q [snip] >> Now options.keys returns ["Password", "Host", "Port", "Name"] >> >> I would expect ["Host", "Port", "Name", "Password"] >> >> is there an explanation for this ? > > Yes: the order of hash keys is not guaranteed. I *think* #keys > returns the keys in the same order when called multiple times, but I'm > not 100% sure. In any case, that order itself cannot be predicted. > > I believe various people have written various OrderedHash > extensions... (very helpful advice, I know :-) You could search on > to see if there's been discussion here. Theres one at http://sourceforge.net/projects/rubycollections/ Look for rubycollections/rbc/sorted_hash.rb under CVS. Jason Voegele