From: Brian Candler Date: 2004-10-05T22:27:07+09:00 Subject: Re: [RCR] New [] Semantics On Tue, Oct 05, 2004 at 10:10:12PM +0900, Florian Frank wrote: > Hmm, i just got another idea, how it would be able to always return > true or false > for non-Float ranges: > > def member?(x) > include?(x) and > Enumerable.instance_method(:member?).bind(self).call(x) > end Hmm, but (0..1.0/0).member?(99999999) would still take an inordinate amount of time. For ranges which start with integers we can do better: def member?(x) return false unless include?(x) return false if first.kind_of?(Integer) and x.to_i != x true end but then this is special-casing. Incidentally, I realised that treating ranges as enumerable isn't going to make sense for infinite lower bounds: (-1.0/0..100).member?(0) I suppose the iterator could work backwards in this case. Unfortunately, Ruby does not define a "pred" or "prev" being the reverse of "succ", so I can't see a general solution. I start to feel that ranges of discrete items and ranges of the form a <= b < c are substantially different... Regards, Brian.