From: Peter Date: 2003-11-27T11:05:24+09:00 Subject: Re: Range does not take an Range object. > class Range > alias_method :original_include?, :include? > > def include?(other) > return original_include?(other) unless other.is_a?(Range) > return other.first >= first && other.last <= last > end > > def intersect?(other) > return true if include?(other) > return include?(other.last) || include?(other.first) || other.include?(first) || other.include?(last) > end > end It should indeed really be built in, because the presence of exclude_end? and empty ranges make things really complicated. If I could disregard these issues, I'd implement intersect? as def intersect?(other) return last >= other.first && other.last >= first end (I had to do that for an assignment in college once, it's weird but correct; it basically says self is not all smaller than other, and other is not all smaller than self.) But that it's hard is illustrated by the current implementation itself, e.g., irb(main):001:0> (1...1).max => nil irb(main):002:0> ("1"..."1").max => "1" which seems inconsistent (the inconsistency is because of an inconsistency in each). Another funny thing is that (1..10000000000).member? 9999999999 takes ages to complete, though (1..10000000000).include? 9999999999 completes immediately. Still member? is a synonym for include?, or at least Programming Ruby says so. But I guess I'm the only one interested in numbers like 10000000000 :-) Peter