From: Mark Hubbart Date: 2005-05-03T04:03:47+09:00 Subject: Re: enum in ruby ? On 5/2/05, Andreas Habel wrote: > Hi, > > I`ve a simple question about constants in ruby. Is there a possibility > to define constants in a module or a class like a enum in c? Others have given good direct solutions... But I wonder why you would want this? For most situations, symbols would be a cleaner solution: MyClass.new(data, MyClass::CONST_A1, MyClass::CONST_B3) vs. MyClass.new(data, :a1, :b2) They can also be used as flags: MyClass.new(data, MyClass::CONST_A1 | MyClass::CONST_A2) vs. MyClass.new(data, :a1, :a2) Constants are used in core classes like File and IO, but i think it's mainly due to them being based on the underlying system calls, which use C. ISTM that most rubysts prefer to use symbols for flags and enumerated values. HTH, Mark