Class AutoArray
In: lib/more/facets/autoarray.rb
Parent: Array

An Array that automatically expands dimensions as needed.

  a  = Autoarray.new
  a[1][2][3] = 12
  a             #=> [nil, [nil, nil, [nil, nil, nil, 12]]]
  a[2][3][4]    #=> []
  a             #=> [nil, [nil, nil, [nil, nil, nil, 12]]]
  a[1][-2][1] = "Negative"
  a             #=> [nil, [nil, [nil, "Negative"], [nil, nil, nil, 12]]]

Methods

[]   []=   new  

Public Class methods

[Source]

    # File lib/more/facets/autoarray.rb, line 16
16:   def initialize(size=0, default=nil, update = nil, update_index = nil)
17:     super(size, default)
18:     @update, @update_index = update, update_index
19:   end

Public Instance methods

[Source]

    # File lib/more/facets/autoarray.rb, line 21
21:   def [](k)
22:     if -self.length+1 < k and k < self.length
23:       super(k)
24:     else
25:       Autoarray.new(0, nil, self, k)
26:     end
27:   end

[Source]

    # File lib/more/facets/autoarray.rb, line 29
29:   def []=(k, v)
30:     @update[@update_index] = self if @update and @update_index
31:     super
32:   end

[Validate]