From: Joel VanderWerf Date: 2005-08-03T05:17:59+09:00 Subject: Re: enum collection of constant values Ara.T.Howard wrote: > 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 Why would you want the mc = self.class option ? irb(main):022:0> x=[] => [] irb(main):023:0> x.instance_eval { enum %w{ZZZ AAA} } => ["ZZZ", "AAA"] irb(main):024:0> ZZZ NameError: uninitialized constant ZZZ from (irb):24 irb(main):025:0> Array::ZZZ => 0 -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407