Class: RubyFish::MMatrix

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyfish/mmatrix.rb

Instance Method Summary collapse

Constructor Details

#initialize(nrows, ncolumns) ⇒ MMatrix

Returns a new instance of MMatrix.



3
4
5
# File 'lib/rubyfish/mmatrix.rb', line 3

def initialize nrows, ncolumns
  @rows = Array.new(nrows) { Array.new(ncolumns) {0}}
end

Instance Method Details

#[](i, j) ⇒ Object



7
8
9
# File 'lib/rubyfish/mmatrix.rb', line 7

def [](i, j)
  @rows[i][j]
end

#[]=(i, j, v) ⇒ Object



11
12
13
# File 'lib/rubyfish/mmatrix.rb', line 11

def []=(i, j, v)
  @rows[i][j] = v
end

#each_indexObject



15
16
17
18
19
20
21
# File 'lib/rubyfish/mmatrix.rb', line 15

def each_index
  @rows.each_with_index do |r, i|
    r.each_index do |j|
      yield i, j
    end
  end
end

#each_with_indexObject



23
24
25
26
27
# File 'lib/rubyfish/mmatrix.rb', line 23

def each_with_index
  each_index do |i, j|
    yield self[i, j], i, j
  end
end