From: Brian Candler Date: 2004-10-05T19:05:29+09:00 Subject: Re: Too Many Ways? On Tue, Oct 05, 2004 at 06:28:35PM +0900, trans. (T. Onoma) wrote: > > 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. Errm, well it looks right to me. If you're saying that the range 0...10 is actually the set of integers 0,1,2,3,4,5,6,7,8,9, then 4.3 is not a member of that set; but if you consider it as a continuous range along the number line, then 4.3 is included within that range. And Ruby does indeed recognise the distinction: irb(main):001:0> r = (0...10) => 0...10 irb(main):002:0> r.include?(4.3) => true irb(main):003:0> r.member?(4.3) => false > I'll look at it some more later. Do you see anything in particular that's > problematic with it? I think it will work fine. The problem will be that many more cases will turn up where Infinity should be treated as a special case, for consistency. a[2,Infinity] a[2..Infinity] # currently gives RangeError: float Inf out of range of integer ... probably lots of others And unfortunately we still don't eliminate the smelly ranges where last < first. a = "mystring" a[2..-1] Regards, Brian.