Class: Range

Inherits:
Object show all
Defined in:
lib/puppet/util/monkey_patches.rb

Direct Known Subclasses

Semantic::VersionRange

Instance Method Summary collapse

Instance Method Details

#intersection(other) ⇒ Object Also known as: &

Raises:

  • (ArgumentError)


79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/puppet/util/monkey_patches.rb', line 79

def intersection(other)
  raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)
  return unless other === self.first || self === other.first

  start = [self.first, other.first].max
  if self.exclude_end? && self.last <= other.last
    start ... self.last
  elsif other.exclude_end? && self.last >= other.last
    start ... other.last
  else
    start .. [ self.last, other.last ].min
  end
end