From: "trans. (T. Onoma)" Date: 2004-10-05T19:38:01+09:00 Subject: Re: [RCR] New [] Semantics On Tuesday 05 October 2004 05:59 am, Brian Candler wrote: > Yes, but what you probably want is 'include?' rather than 'member?' Certainly helps to know the distinction (which in unintuitive btw) > Both Range#include? and Range#member? override the methods mixed in from > Enumerable, where those methods are just synonyms for each other. > > This is certainly confusing! Amazing how even the simple things get that way! > I'd say if you want to iterate over the range, then use Enumerable#find or > Enumerable#find_all as appropriate, then get rid of this distinction. Understandable. #member? should just be an alias for #find then and use #between? for other need. At least, that seems the most consistant. > > Yuk. But there is nothing one can do about it as long as one depends on > > #succ. I suppose it's awfully clever and OOP and all to have any object > > supporting <=> and succ work with ranges, but I wonder how much use they > > get outside of numbers and occasional character ranges. In other words > > perhaps succ isn;t the way to go (or perhaps a fallback) and a simple > > increment/decrement in the Range itself would be more usable --then the > > above 7 minutes would be about 7 milliseconds. > > If you're going to rely on increment/decrement then I'm pretty sure you can > also rely on the mathematic properties of < and >, i.e. just compare the > boundary values as 'include?' does. > > Besides, > a = a.succ > and > a = a + 1 > take almost identical amounts of time, since even '+ 1' involves a method > dispatch: > a = a.send(:+,1) With inc/dec modulo can be used. Something like: def member?(e) return ( (((e + self.begin) % @increment) == 0) && self.between?(e) ) end T.