aboutsummaryrefslogtreecommitdiffstats
path: root/lib/range_ext.rb
diff options
context:
space:
mode:
authorAlban Peignier2017-12-27 21:23:07 +0100
committerAlban Peignier2018-01-05 10:23:29 +0100
commit7a65a9fbe0cefdf504e7d735003065d8bb874f1e (patch)
tree0763c07455253e3fdc6ed47d503a2cbbf03c5efc /lib/range_ext.rb
parent97a9a7d921d412fd8300c9d84e719ee494079c3b (diff)
downloadchouette-core-7a65a9fbe0cefdf504e7d735003065d8bb874f1e.tar.bz2
Add Range#intersect?. Refs #5299
Diffstat (limited to 'lib/range_ext.rb')
-rw-r--r--lib/range_ext.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/range_ext.rb b/lib/range_ext.rb
index a6a3bfc5d..e7e0e903f 100644
--- a/lib/range_ext.rb
+++ b/lib/range_ext.rb
@@ -1,11 +1,15 @@
class Range
def intersection(other)
- return nil if (self.max < other.min or other.max < self.min)
+ return nil unless intersect?(other)
[self.min, other.min].max..[self.max, other.max].min
end
alias_method :&, :intersection
+ def intersect?(other)
+ self.max > other.min and other.max > self.min
+ end
+
def remove(other)
return self if (self.max < other.min or other.max < self.min)