From: Logan Capaldo Date: 2006-03-10T08:01:54+09:00 Subject: Re: Enums (was: My Ruby talk @ work..) On Mar 9, 2006, at 9:33 AM, Florian Gro� wrote: > Logan Capaldo wrote: > >> The idiom I usually use is: >> class HockeyGear >> Stick = Object.new >> Helmet = Object.new >> ...etc... >> end >> Of course other than the aesthtics of looking like an enum >> (HockeyGear::Stick) in the source code there's no advantage over >> symbols. On the other hand, if someone is passing you an enum, it >> probably means any one of the enums is valid, so you should be >> checking all of them anyway, and throw an exception in the else >> clause. Checking whether an object is of the right type isn't >> very ruby-like anyway. > > Hm, I wrote the attached Enum class a while ago. What do you think? > > -- > http://flgr.0x42.net/ > Looks pretty cool. I question this though: symbol = symbol.to_s.sub(/^[a-z]/) { |letter| letter.upcase }.to_sym Why not just: symbol = symbol.to_s.capitalize.to_sym ?