Class: Range
Instance Method Summary collapse
-
#&(other) ⇒ Object
Return a new range which is the intersection of the two ranges.
-
#mid ⇒ Object
(also: #middle)
The number in the middle of this range.
-
#rand ⇒ Object
Pick a random number from the range.
-
#|(other) ⇒ Object
Return a new range which is the union of the two ranges.
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 |
#mid ⇒ Object 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 |
#rand ⇒ Object
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 |