From f90488de1f657abf24026231485c87d3e42ee11d Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Sun, 17 Dec 2017 15:31:47 +0100 Subject: Move (clean) period split logic into Range#remove. Refs #5299 --- lib/range_ext.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/range_ext.rb b/lib/range_ext.rb index f1df5e70d..a6a3bfc5d 100644 --- a/lib/range_ext.rb +++ b/lib/range_ext.rb @@ -5,4 +5,16 @@ class Range [self.min, other.min].max..[self.max, other.max].min end alias_method :&, :intersection + + def remove(other) + return self if (self.max < other.min or other.max < self.min) + + [].tap do |remaining| + remaining << (self.min..other.min-1) if self.min < other.min + remaining << (other.max+1..self.max) if other.max < self.max + remaining.compact! + end + end + alias_method :-, :remove + end -- cgit v1.2.3