From: James Edward Gray II Date: 2006-04-17T08:11:38+09:00 Subject: Re: Simple Enumerations in Rub On Apr 16, 2006, at 2:55 PM, Rusty Geldmacher wrote: > http://www.soapboxsoftware.org/articles/2006/04/15/a-simple- > enumeration-pattern-for-ruby > > I would greatly appreciate feedback from the Ruby community! Quoted from the article: "That in itself is not a very challenging or interesting problem. We can certainly create a class with a list of constants, such as in the example below. class Direction North = 0 East = 1 West = 2 South = 3 end Though simple, this solution does not satisfy our design goals. For one, it makes it nearly impossible to reverse map values. With that class above, how would I determine that the number 2 corresponds to the value �West�?" Reflection: >> class Direction >> North = 0 >> East = 1 >> West = 2 >> South = 3 >> end => 3 >> Direction.constants.find { |c| Direction.const_get(c) == 2 } => "West" "Another goal it does not satisfy is the ability to iterate through the members of the enumeration." >> Direction.constants.each { |c| puts "#{c} = #{Direction.const_get (c)}" } South = 3 West = 2 East = 1 North = 0 => ["South", "West", "East", "North"] Both of those are just FYI. I did enjoy reading the article. :) James Edward Gray II