Sha256: 62ccf69770fbeaa3e2b2e03e60a76a2133a259d407c37f25b6d0bd541f26b3a4
Contents?: true
Size: 523 Bytes
Versions: 14
Compression:
Stored size: 523 Bytes
Contents
class Range # # Pick a random number from the range. # def rand Kernel.rand(self) end # # The middle element of this range. # def middle (min + max) / 2 end # # Return a new range which is the intersection of the two ranges # def &(other) mins, maxes = minmax.zip(other.minmax) (mins.max..maxes.min) end # # Return a new range which is the union of the two ranges # def |(other) mins, maxes = minmax.zip(other.minmax) (mins.min..maxes.max) end end
Version data entries
14 entries across 14 versions & 1 rubygems