From: Garance A Drosehn Date: 2005-08-03T10:49:04+09:00 Subject: Re: enum collection of constant values On 8/2/05, Ara.T.Howard wrote: > hmm. this is a bit shorter > class Object > def enum(*list) > mc = Module === self ? self : self.class > list.flatten.each_with_index{|e, i| mc.const_set e.to_s.intern, i} > end > def bit_enum(*list) > mc = Module === self ? self : self.class > list.flatten.each_with_index{|e, i| mc.const_set e.to_s.intern, 2 ** i} > end > end I changed the method names to enum_constants and enum_bit_constants. > probably could also combine this idea with the Enum module... I wasn't sure what you meant by this. I tried changing the above to be 'class Enum", and then have the method names be "Enum.constants" and "Enum.bit_constants", but that didn't seem to work. I checked Pickaxe 2, RAA, and RubyForge for an Enum module, but didn't come up with anything. Then again, this is the first time I tried searching RAA or RubyForge for some module, so I'm probably doing it wrong... -- Garance Alistair Drosehn = drosihn@gmail.com Senior Systems Programmer or gad@FreeBSD.org Rensselaer Polytechnic Institute; Troy, NY; USA