----- Original Message ----- 
From: "Philip Mak" <pmak / aaanime.net>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
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