On Wed, 15 Mar 2000, Clemens Hintze wrote: > solve your special problem. But I cannot resist to show you an > example, that realize a Enumeration like type as in Pascal or > C++. :-))) > > def Enumeration(*args) > args << :dummy > mod = Module.new > name, value = "", -1 > for arg in args > raise SyntaxError, "Enumerator have to begin with [A-Z]: (#{name})" \ > unless name.capitalize == name > mod.module_eval "#{name} = #{value}" unless name.empty? > if arg.type == String > name, value = arg, value+1 > elsif arg.type == Symbol > name, value = arg.id2name, value+1 > elsif arg.type <= Numeric > value = arg > else > raise TypeError > end > end > mod > end This looks interesting. I will have to study it closely. > > You could use this method like: > > spam = Enumeration("Gnark",2, "Blubb",7, "Foo", :Bar, :Foobar) > > Then you may access such a constant via e.g.: > > spam::Blubb > spam::Bar > ... > > This definition would be written in C++ as: > > enum spam { Gnark=2, Blubb=7, Foo, Bar, Foobar }; > So I think I would need another type to allow variables to ony accept values and bitwise OR's of values from such a type, and nothing outside that range. I'll give this more thought. > ... > -- > Clemens Hintze mailto: c.hintze / gmx.net > Thank you, Hugh hgs / dmu.ac.uk