From: Paul Brannan Date: 2003-09-16T03:21:51+09:00 Subject: Re: Implementing the tape safe enum pattern in Ruby. On Tue, Sep 16, 2003 at 01:47:46AM +0900, Ged wrote: > I rather like the type safe enum pattern in Java, and I was wonding > how I might implement it in Ruby. Here is an example (based on the > earlier OO challange thread). > > The big advantage is that it allows me to dynamically specify a > domain. Iteration and lookup comes free, all I have to do is declare > each variation. I find constant use for it, avoiding the need for > reflection. Yes, this is possible in Ruby. See: http://cvs.sf.net/cgi-bin/viewcvs.cgi/rubycollections/rubycollections/rbc/enum.rb?rev=1.7 http://cvs.sf.net/cgi-bin/viewcvs.cgi/excruby/excruby/excruby/enum_wrapper.hpp?rev=1.2 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/79041 > Is an equivalent possible in Ruby, or is it irrelevant because Ruby is > not strongly typed? Ruby is strongly typed. It is not statically typed. See [ruby-talk:64625]. Paul