Class: Range

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/core_ext.rb

Instance Method Summary collapse

Instance Method Details

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

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/ext/core_ext.rb', line 12

def intersection(other)
  raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)
  return nil if (self.max < other.begin or other.max < self.begin) 
  [self.begin, other.begin].max..[self.max, other.max].min
end