From: Bill Atkins Date: 2005-05-03T02:45:59+09:00 Subject: Re: enum in ruby ? ------=_Part_8642_26450347.1115055939005 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Don't know if there's anything built-in, but you can try (untested): [:CONST_1, :CONST_2].each_with_index { |name, i| eval name.to_s + " =3D " += (i=20 + 1).to_s } On 5/2/05, Andreas Habel wrote: >=20 > Hi, >=20 > 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? >=20 > Maybe something short like the 'attr_accessor' syntax would be great! >=20 > class MyClass > const_def :CONST_A1, :CONST_A2, :CONST_A3 > const_def :CONST_B1, :CONST_B2, :CONST_B3 > end >=20 > eq. >=20 > class MyClass >=20 > CONST_A1 =3D 1 > CONST_A2 =3D 2 > CONST_A3 =3D 3 >=20 > CONST_B1 =3D 1 > CONST_B2 =3D 2 > CONST_B3 =3D 3 > end >=20 > Thanks, > Andreas >=20 >=20 --=20 Bill Atkins ------=_Part_8642_26450347.1115055939005--