Class: Range

Inherits
Object show all
Defined in
lib/kyanite/range.rb,
lib/kyanite/enumerable/structure.rb

Range Additions

Kyanite definitions

Range

Kyanite tests and examples

TestKyaniteRange

Usage

require 'kyanite/range'

Added from Facets Range:

umbrella(range)

Returns a two element array of the relationship between two Ranges

within? (range)

Is another Range anywhere within this Range?

combine(range)

Combine ranges

Instance Method Summary (collapse)

Instance Method Details

- (Range) invert_index

Given a range for selecting a section of a String or an Array, invert_index inverts this range, so that the result selects the inverse part of the String or Array.

Tests and more examples here.

Examples:

# return back 
(0..5).invert_index
=> (6..-1)

# return front 
(3..-1).invert_index
=> (0..2)

# return outer
(2..4).invert_index
=> [0..1,   5..-1]

Returns:

  • (Range)

    or [Array] of two Ranges



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kyanite/range.rb', line 47

def invert_index

  # back
  if first == 0
    return (1..0)           if last == -1     # leer
    return (last+1..-1)                       # hinterer Teil

  # front
  else 
    return (0..first-1)     if last == -1     # vorderer Teil
    
  end
  
  # outer
  return [(first..-1).invert_index, (0..last).invert_index]
end

- (false) is_collection?

false -- Defined for all objects: Do I contain multiple objects? String and Range are not considered as collection.

Tests and examples here.

Returns:

  • (false)


36
# File 'lib/kyanite/enumerable/structure.rb', line 36

def is_collection?;                 false;          end