Combine intervals.
Range.combine(1..2, 2..4) #=> [1..4] Range.combine(1..2, 3..4) #=> [1..2, 3..4]
CREDIT: Trans
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
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
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