diff options
Diffstat (limited to 'lib/range_ext.rb')
| -rw-r--r-- | lib/range_ext.rb | 12 | 
1 files changed, 12 insertions, 0 deletions
| 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 | 
