Created
February 25, 2013 13:55
-
-
Save kvzb/5029933 to your computer and use it in GitHub Desktop.
Comparing two ranges for intersections. Returns a Range if they intersect, or nil.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Range | |
def intersection(other) | |
return nil if (self.max < other.begin or other.max < self.begin) | |
[self.begin, other.begin].max..[self.max, other.max].min | |
end | |
alias_method :&, :intersection | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment