From: Jeff Cohen Date: 2006-03-09T10:34:42+09:00 Subject: Re: My Ruby talk @ work.. Stephen Waits wrote: > I explained that each symbol has a unique ID, and that Ruby uses symbols > to look stuff up within its own system. I believe I had given them > several ".send(:symbol)" examples at that point. And it's much better than the "it's an immutable string" explanation, which I've found to be just a rats nest of problems. Enums are another good analogy. But in C++/C# enums are typed so you know the client gave you a valid value. The only way I can see to enforce this in Ruby is to create a constant array of the valid symbols and then make sure what they passed me is in the array: class HockeyGear BuyableGear = [ :stick, :helmet, :skates ] def self.buy_something(gear) if (!BuyableGear.include?(gear)) return nil end # let them buy something... end end HockeyGear.buy_something(:soccer_ball) # returns nil Somehow I feel this is pretty un-rubylike, to have to have that if statement in front of every method. Any idea if there's a more ruby-like way to have enum-like behavior? Thanks Jeff -- Posted via http://www.ruby-forum.com/.