Class: StaticArray
- Inherits:
-
Object
- Object
- StaticArray
- Defined in:
- lib/simms_structures/static_array.rb
Overview
This class just dumbs down a regular Array to be staticly sized.
Instance Method Summary collapse
-
#[](index) ⇒ Object
O(1).
-
#[]=(index, value) ⇒ Object
O(1).
-
#initialize(length) ⇒ StaticArray
constructor
A new instance of StaticArray.
Constructor Details
#initialize(length) ⇒ StaticArray
Returns a new instance of StaticArray.
3 4 5 |
# File 'lib/simms_structures/static_array.rb', line 3 def initialize(length) @store = Array.new(length, nil) end |
Instance Method Details
#[](index) ⇒ Object
O(1)
8 9 10 |
# File 'lib/simms_structures/static_array.rb', line 8 def [](index) @store[index] end |
#[]=(index, value) ⇒ Object
O(1)
13 14 15 16 |
# File 'lib/simms_structures/static_array.rb', line 13 def []=(index, value) check_index(index) @store[index] = value end |