[#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:01837] Re: enum examples?

From: Hugh Sasse Staff Elec Eng <hgs@...>
Date: 2000-03-15 14:02:45 UTC
List: ruby-talk #1837
On Wed, 15 Mar 2000, Clemens Hintze wrote:

> Hugh Sasse Staff Elec Eng writes:
> > Has anyone any examplse of using the Enumerable module?  I've had a 
> > look around, but not found much.  I'm thinking of something to allow
> > me to have names for bits in a flag field, so I can test if one or
> > more is set.
> 
> Hi,
> 
> if I have not misunderstood your question, I think you have
> misunderstood the purpose of module Enumerable ;-)))
> 
> Enumerable offers some methods like: min, max, sort, ... that could be
> included into any class that provide the method 'each'. After
> including, the class get all methods of Enumerable for free ...

So that is all.  I saw a bunch of methods based on each but was not
sure how that imeplemented enumerated types -- I learnt Pascal years
ago (yikes! :-) it's nearly 18 years!) so that is the concept I had in
mind, it clearly has stuck
> 
> Classes Array or IO of the standard lib, include Enumerable for
> example. Here is a another one:
> 
	[nice example trimmmed]
> 
> You can see, although there is no method 'max' or 'to_a' defined for
> MyRange, any instance can use them, because they are coming from
> Enumerable. As you can include more than one module, it is somewhat
> similar with multiple inheritance. But cleaner, IMHO.
> 
	Thank you.

> > I could create my own object for this, of course, but
> > why re-invent unless I must?
> 
> Here, I think, it would not be re-invention but invention. There is no
> such class, AFAIK.

	OK.  I will see if I can generalise this when I create it.
> 
> \cle
> 
	Thank you
	Hugh
	hgs@dmu.ac.uk


In This Thread