[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:01905] Re: Enumerations and all that.

From: Hugh Sasse Staff Elec Eng <hgs@...>
Date: 2000-03-16 17:16:06 UTC
List: ruby-talk #1905
On 16 Mar 2000, Dave Thomas wrote:

> Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:
> 
> > Thank you to the people who responded to my questions about
> > Enumerated types.  I have put something together that does what I
> > want now, and have some code to (not rigorously) test it.  It may
> > have major weaknesses that I have not seen, so I would welcome
> > comments on it.
> 
> I was wondering: if, rather than making each enumeration an instance,
> you were instead to define a new class for it (probably itself a
> subclass of Enumeration), then there'd be no need for the rest of the
> user-level code to keep an object reference lying around. You could
> say something like

I am not sure how to do that on the fly.  In what binding can I 
eval("class #{enum_nam}...end",???)
to create the new class?

> 
>    Enumeration.create("Colours", { RED => 1, GREEN => 2, ... })

then I need another instance of class (Pascal would call it a VAR in
contrast to my enum TYPE) which can hold values only available in the enum
type.  That latter type would alow operations on it rather than
declaration. I thought it simpler to keep them together, and use the
@_value to access the VAR.
> 
> and then elsewhere in the code simply reference
> 
>     Colours::RED
>     Colours::GREEN
> 
> and so on.
> 
> If you wanted to go that route, the method Module#const_set would be
> useful.

I don't really understand this.  Each instance needs to be tied to some
enumeraton class, so it only holds values allowed in that enum, but if I
have a Module then I cannot have instances of a Module, because the FAQ
says that is the difference between Module and Class.  If it is to have a
readonly thing within each class that is stored in one place, I wondered
if I caould do that by making @_fields into Enumeration.fields, so it is a
class variable, but I could not get that to work.  I am only sure that
class methods and singleons can be make to exist, not class variables
shared across all instances.
> 
> Regards
> 
> 
> Dave
> 
	Hugh
	hgs@dmu.ac.uk


In This Thread