module Torque::Range

Public Instance Methods

&(other)
Alias for: intersection
intersection(other) click to toggle source
# File lib/torque/range.rb, line 3
def intersection(other)
  raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)

  new_min = self.cover?(other.min) ? other.min : other.cover?(min) ? min : nil
  new_max = self.cover?(other.max) ? other.max : other.cover?(max) ? max : nil

  new_min && new_max ? new_min..new_max : nil
end
Also aliased as: &
union(other) click to toggle source
# File lib/torque/range.rb, line 13
def union(other)
  raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)

  ([min, other.min].min)..([max, other.max].max)
end
Also aliased as: |
|(other)
Alias for: union