From: "Hal E. Fulton" Date: 2002-08-27T07:26:41+09:00 Subject: Re: Hybrid hash and array? ----- Original Message ----- From: "Philip Mak" To: "ruby-talk ML" Sent: Monday, August 26, 2002 5:14 PM Subject: Hybrid hash and array? > When programming radio buttons on a website, I find myself using this > sort of construct a lot: > > @choices = [ > ['1', 'Spring'], > ['2', 'Summer'], > ['3', 'Fall'] > ] > > @table = {} > @choices.each do |key, value| > @table[key] = value > end > > The data structure I really want is like a hash, except that it > maintains its key/value pairs in the order that I defined them. You could always use Array#assoc... @choices.assoc('1')[1] # 'Spring' @choices.assoc('3')[1] # 'Fall' Hal