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

Version Path
epitools-0.5.57 lib/epitools/core_ext/range.rb
epitools-0.5.56 lib/epitools/core_ext/range.rb
epitools-0.5.55 lib/epitools/core_ext/range.rb
epitools-0.5.54 lib/epitools/core_ext/range.rb
epitools-0.5.51 lib/epitools/core_ext/range.rb
epitools-0.5.50 lib/epitools/core_ext/range.rb
epitools-0.5.49 lib/epitools/core_ext/range.rb
epitools-0.5.47 lib/epitools/core_ext/range.rb
epitools-0.5.46 lib/epitools/core_ext/range.rb
epitools-0.5.45 lib/epitools/core_ext/range.rb
epitools-0.5.44 lib/epitools/core_ext/range.rb
epitools-0.5.43 lib/epitools/core_ext/range.rb
epitools-0.5.42 lib/epitools/core_ext/range.rb
epitools-0.5.41 lib/epitools/core_ext/range.rb