Class: Matriz_densa

Inherits:
Matriz show all
Defined in:
lib/matrices/matriz_densa.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matriz

#*, #+, #-, #coerce, #max, #min, nula, #to_s, vector

Constructor Details

#initialize(rows, cols, ele) ⇒ Matriz_densa

Returns a new instance of Matriz_densa.



6
7
8
9
10
# File 'lib/matrices/matriz_densa.rb', line 6

def initialize(rows, cols, ele)
  super(rows, cols)
  @mat=Array.new(ele)
  @mat.map! {|e|; if e == e.elemento_nulo; e = 0; else e; end}
end

Instance Attribute Details

#colsObject (readonly)

Returns the value of attribute cols.



4
5
6
# File 'lib/matrices/matriz_densa.rb', line 4

def cols
  @cols
end

#rowsObject (readonly)

Returns the value of attribute rows.



4
5
6
# File 'lib/matrices/matriz_densa.rb', line 4

def rows
  @rows
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/matrices/matriz_densa.rb', line 24

def ==(other)
  if (@rows != other.rows || @cols != other.cols)
    return false
  end
  for i in 0...@rows
    for j in 0...@cols
      if (@mat[pos(i,j)] != other[i,j])
        return false
      end
    end
  end
  return true
end

#[](x, y) ⇒ Object



16
17
18
# File 'lib/matrices/matriz_densa.rb', line 16

def [](x,y)
  @mat[pos(x,y)]
end

#[]=(x, y, value) ⇒ Object



20
21
22
# File 'lib/matrices/matriz_densa.rb', line 20

def []=(x,y,value)
  @mat[pos(x,y)] = value
end

#pos(x, y) ⇒ Object



12
13
14
# File 'lib/matrices/matriz_densa.rb', line 12

def pos(x,y)
  (x*@cols)+y
end