From: dblack@... Date: 2007-02-21T09:04:57+09:00 Subject: Re: [Facets] Range#overlap? Hi -- On Wed, 21 Feb 2007, Daniel Schierbeck wrote: > On Wed, 2007-02-21 at 08:00 +0900, Daniel Finnie wrote: >> I think your implementation is cleaner however the endpoints of a Range >> do not have to implement #succ. >> >> class Range >> def span? other >> include? other.first and >> (other.exclude_end? ? other.last < last : other.last <= last ) >> end >> end > > I've tried that implementation, but i doesn't work if you consider this > valid: > > (4..8).span? 6...9 > > Since 6...9 yields the same values as 6..8. Or am I wrong to expect the > above? I don't think ranges really yield values. Some of them can be converted to arrays, but a range qua range is really just two endpoints, between which everything comparable to those endpoints either is or isn't. I'm not sure I have my head around what span? is supposed to be doing. Can you write some test cases? I keep thinking of this: include?(other.first) and include?(other.last) but I don't think that's what you're trying to do with span?. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)