Method: Range#&

Defined in:
lib/combinatorics/extensions/range.rb

#&(other) ⇒ Range

Finds the intersecting sub-range.

Examples:

(1..100) & (20..200)
# => 20..100

Parameters:

  • other (Range)

    The other range.

Returns:

  • (Range)

    The intersecting sub-range.

Since:

  • 0.2.0



20
21
22
23
24
25
# File 'lib/combinatorics/extensions/range.rb', line 20

def &(other)
  Range.new(
    [self.first, other.first].max,
    [self.last, other.last].min
  )
end