class StaticArray

This class just dumbs down a regular Array to be staticly sized.

Attributes

store[RW]

Public Class Methods

new(length) click to toggle source
# File lib/simms_structures/static_array.rb, line 3
def initialize(length)
  @store = Array.new(length, nil)
end

Public Instance Methods

[](index) click to toggle source

O(1)

# File lib/simms_structures/static_array.rb, line 8
def [](index)
  @store[index]
end
[]=(index, value) click to toggle source

O(1)

# File lib/simms_structures/static_array.rb, line 13
def []=(index, value)
  check_index(index)
  @store[index] = value
end

Private Instance Methods

check_index(idx) click to toggle source
# File lib/simms_structures/static_array.rb, line 20
def check_index(idx)
  raise TypeError 'Invalid Position' if 0 > idx || idx > @store.length
end