Class: Array

Inherits:
Object show all
Defined in:
lib/flex_array/array.rb

Overview

Extensions to Array needed to support flex array.

Direct Known Subclasses

SpecArray

Instance Method Summary collapse

Instance Method Details

#array_dataObject

Quick access to the array data for internal use.



15
16
17
# File 'lib/flex_array/array.rb', line 15

def array_data
  self
end

#array_specsObject

Quick access to the limits for internal use.



10
11
12
# File 'lib/flex_array/array.rb', line 10

def array_specs
  SpecArray.new([0...self.length])
end

#limitsObject

Get the specifications of the array index values.



5
6
7
# File 'lib/flex_array/array.rb', line 5

def limits
  [0...self.length]
end

#to_flex_arrayObject

Return this flex array as a flex array!



36
37
38
# File 'lib/flex_array/array.rb', line 36

def to_flex_array
  FlexArray.new_from_array(self)
end

#to_index_range(spec) ⇒ Object

Convert this array to an range index against the spec.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/flex_array/array.rb', line 20

def to_index_range(spec)
  spec_max = spec.max

  self.collect do |value|
    value = Integer(value)
    value = spec_max + value + 1 if value < 0

    unless spec === value
      fail IndexError, "Subscript invalid or out of range: #{self.inspect}"
    end

    value
  end
end