From: "David A. Black" Date: 2009-01-12T21:26:30+09:00 Subject: Re: sort hash, hash key and val off by one, see attached Hi -- On Mon, 12 Jan 2009, Dave Bass wrote: > Mmcolli00 Mom wrote: >> I just need to somehow find the next key in a hash > > I haven't read your example, but this statement rings alarm bells. You > need to define what you mean by "the next key". A hash has no natural > ordering -- it's just a bunch of key-value pairs -- so it's not obvious > what the "next" key means. The order in which you insert pairs is not > necessarily the order in which you get them back, and this order may > vary from one run to the next. This is basic to hashes. It's changing in 1.9, though. 1.9 hashes are ordered by key insertion order. $ ruby -ve 'p({1=>"hi", "a"=>"bye", []=>"whatever"})' ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-darwin9.5.0] {[]=>"whatever", "a"=>"bye", 1=>"hi"} $ ruby19 -ve 'p({1=>"hi", "a"=>"bye", []=>"whatever"})' ruby 1.9.1 (2008-12-30 patchlevel-0 revision 21203) [i386-darwin9.5.0] {1=>"hi", "a"=>"bye", []=>"whatever"} David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) http://www.wishsight.com => Independent, social wishlist management!