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

Version Path
epitools-0.5.94 lib/epitools/core_ext/range.rb
epitools-0.5.93 lib/epitools/core_ext/range.rb
epitools-0.5.92 lib/epitools/core_ext/range.rb
epitools-0.5.91 lib/epitools/core_ext/range.rb
epitools-0.5.90 lib/epitools/core_ext/range.rb
epitools-0.5.89 lib/epitools/core_ext/range.rb
epitools-0.5.88 lib/epitools/core_ext/range.rb
epitools-0.5.87 lib/epitools/core_ext/range.rb
epitools-0.5.86 lib/epitools/core_ext/range.rb
epitools-0.5.85 lib/epitools/core_ext/range.rb
epitools-0.5.84 lib/epitools/core_ext/range.rb
epitools-0.5.83 lib/epitools/core_ext/range.rb
epitools-0.5.82 lib/epitools/core_ext/range.rb
epitools-0.5.81 lib/epitools/core_ext/range.rb
epitools-0.5.79 lib/epitools/core_ext/range.rb
epitools-0.5.78 lib/epitools/core_ext/range.rb
epitools-0.5.77 lib/epitools/core_ext/range.rb
epitools-0.5.75 lib/epitools/core_ext/range.rb
epitools-0.5.74 lib/epitools/core_ext/range.rb
epitools-0.5.73 lib/epitools/core_ext/range.rb