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)


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/puppet/util/monkey_patches.rb', line 71

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