Class: DS::Array2D
- Inherits:
-
Object
- Object
- DS::Array2D
- Defined in:
- lib/ds/matrixes/array_2d.rb
Overview
Implements two dimensional array.
Instance Method Summary collapse
- #[](x, y) ⇒ Object
- #[]=(x, y, v) ⇒ Object
-
#initialize(size = 1, init = 0) ⇒ Array2D
constructor
Creates new two dimensional array.
- #to_a ⇒ Object
Constructor Details
Instance Method Details
#[](x, y) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ds/matrixes/array_2d.rb', line 14 def [](x,y) if @store[x].nil? @store[x] = [] @init elsif @store[x][y].nil? @init else @store[x][y] end end |
#[]=(x, y, v) ⇒ Object
25 26 27 28 |
# File 'lib/ds/matrixes/array_2d.rb', line 25 def []=(x,y,v) @store[x] = [] if @store[x].nil? @store[x][y] = v end |
#to_a ⇒ Object
30 31 32 |
# File 'lib/ds/matrixes/array_2d.rb', line 30 def to_a @store.flatten end |