Sha256: 0161f5bdd16dbca868995bdf7046e4a76ce006da530a7770d7ebd08426e1f8e7
Contents?: true
Size: 555 Bytes
Versions: 34
Compression:
Stored size: 555 Bytes
Contents
class Range # # Pick a random number from the range. # def rand Kernel.rand(self) end # # The number in the middle of this range. # def mid (min + max) / 2 end alias_method :middle, :mid # # 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
34 entries across 34 versions & 1 rubygems