Class Range
In: lib/core/facets/range/overlap.rb
lib/core/facets/range/quantile.rb
lib/core/facets/range/combine.rb
lib/core/facets/range/to_rng.rb
lib/core/facets/range/nudge.rb
lib/core/facets/range/op_sub.rb
lib/core/facets/range/op_add.rb
lib/core/facets/range/within.rb
lib/standard/facets/random.rb
Parent: Object

Methods

+   -   combine   combine   nudge   overlap?   quantile   to_range   to_rng   umbrella   within?  

Included Modules

Random::RangeExtensions

Public Class methods

Combine intervals.

  Range.combine(1..2, 2..4)   #=> [1..4]
  Range.combine(1..2, 3..4)   #=> [1..2, 3..4]

CREDIT: Trans

Public Instance methods

Add two ranges to create a range array.

Returns [Array]

CREDIT: monocle

Subtract one range from another producing a range array.

Examples

    (1..10) - (4..6)  => [1..3, 7..10]

    (1..10) - (9..12) => [1..8]

Returns [Array]

CREDIT: monocle

Combine ranges.

  (1..2).combine(2..4)   #=> [1..4]
  (1..2).combine(3..4)   #=> [1..2, 3..4]

TODO: Incorporate end-sentinal inclusion vs. exclusion.

CREDIT: Trans

Nudge range values

  (1..5).nudge           #=> 2..6
  (1..5).nudge(2)        #=> 3..7
  (1..5).nudge(-2)       #=> -1..3
  (1..5).nudge(min: 1)   #=> 2..5
  (1..5).nudge(max: 1)   #=> 1..6

CREDIT: Codeindulgence

Do two ranges overlap?

CREDIT: Daniel Schierbeck, Brandon Keepers

Calculate the kth n-tile in a range.

If n=4 the quantity is called a quartile, and if n=100 it is called a percentile.

@uncommon

  require 'facets/range/quantile'

@return [Integer] the kth n-tile

A thing really should know itself. This simply returns self.

Note: This does not internally effect the Ruby interpretor such that it can coerce Range-like objects into a Range.

CREDIT: Trans

A thing really should know itself. This simply returns self.

CREDIT: Trans

Returns a two element array of the relationship between two Ranges.

Diagram …

    Relationship     Returns

  self |-----------|
  r    |-----------|    [0,0]

  self |-----------|
  r     |---------|     [-1,-1]

  self  |---------|
  r    |-----------|    [1,1]

  self |-----------|
  r     |----------|    [-1,0]

  self |-----------|
  r     |-----------|   [-1,1]

  etc.

Example:

  (0..3).umbrella(1..2)  #=>  [-1,-1]

CREDIT: Trans, Chris Kappler

Uses the Range#umbrella method to determine if another Range is anywhere within this Range.

  (1..3).within?(0..4)  #=> true

CREDIT: Trans

[Validate]