Class: Range

Inherits:
Object show all
Defined in:
lib/epitools/core_ext/range.rb

Instance Method Summary collapse

Instance Method Details

#&(other) ⇒ Object

Return a new range which is the intersection of the two ranges



21
22
23
24
25
# File 'lib/epitools/core_ext/range.rb', line 21

def &(other)
  mins, maxes = minmax.zip(other.minmax)

  (mins.max..maxes.min)
end

#midObject Also known as: middle

The number in the middle of this range.



13
14
15
# File 'lib/epitools/core_ext/range.rb', line 13

def mid
  (min + max) / 2
end

#randObject

Pick a random number from the range.



6
7
8
# File 'lib/epitools/core_ext/range.rb', line 6

def rand
  Kernel.rand(self)
end

#|(other) ⇒ Object

Return a new range which is the union of the two ranges



30
31
32
33
34
# File 'lib/epitools/core_ext/range.rb', line 30

def |(other)
  mins, maxes = minmax.zip(other.minmax)

  (mins.min..maxes.max)
end