Nice Brian!

On Tuesday 05 October 2004 04:36 am, Brian Candler wrote:
> According to PickAxe v1, both include? and member? come from Enumerable,
> and are just aliases for each other. Clearly this is not the case in 1.8.x
> any more.
>
> Looking at the source, I see that Range#member? iterates using the 'each'
> function, whereas Range#include? just compares against the start and end
> values.
>
> I think it's a bug that Range#member? doesn't do a 'break' when it finds a
> match. OTOH, I guess it's pretty dubious to be relying on Enumerable-type
> methods over an infinite enumeration :-)

I see! Well, yes it is a bug (IMHO). Moreover #include? should be the same as 
#member?  According to this, what #include? is doing now it really something 
different: #between?

irb(main):002:0> r = (0...10)
=> 0...10
irb(main):003:0> r.include?(4.3)
=> true

Which isn't really right. Of course the problem is per my last post.

> Anyway, on to a quick implementation. 'Infinity' printed by Float#to_s is
> not actually available as a constant:
>
> irb(main):002:0> 1.0/0
> => Infinity
> irb(main):003:0> Infinity
> NameError: uninitialized constant Infinity
>         from (irb):3
>
> but I'm going to break normal class encapsulation by defining it as one at
> the top level anyway, instead of as Range::Infinity. Simple listing
> attached below.

Works for me.

> [snip]
>
> If this went into the core, there would be some syntactic sugar which could
> be done: e.g.  (1..) becomes a synonym for (1..Infinity)

At the very least I'll add it my library. I have quite an extensive 
collection, that I may realease one day.

I'll look at it some more later. Do you see anything in particular that's 
problematic with it?

T.