class Matrices::Matrices
Attributes
datos[R]
m[R]
n[R]
Public Class Methods
new(m=1,n=1,opcion=0)
click to toggle source
# File lib/Matrices/matrices.rb, line 7 def initialize(m=1,n=1,opcion=0) @m,@n = m,n @datos = Array.new(m) for i in 0...@n do @datos[i] = Array.new(@n) end if (opcion == 1) #Rellenamos la matriz con valores aletarios setRandom else for i in 0...opcion.size do @datos[i] = opcion[i] end end #Imprimimos la matriz puts(self) end
Public Instance Methods
<=>(other)
click to toggle source
Overwritting del metodo <=> para el modulo Comparable
# File lib/Matrices/matrices.rb, line 41 def <=>(other) return (@m <=> other.m) && (@n <=> other.n) end
each() { |datos[j]| ... }
click to toggle source
Overwritting del metodo each
# File lib/Matrices/matrices.rb, line 33 def each for i in 0...@m do for j in 0...@n do yield @datos[i][j] end end end
setRandom()
click to toggle source
Metodo que inicia la matriz con valores aleatorios
# File lib/Matrices/matrices.rb, line 25 def setRandom for i in 0...@m do for j in 0...@n do @datos[i][j] = rand(100) end end end
to_s()
click to toggle source
Overwritting del metodo to_s
# File lib/Matrices/matrices.rb, line 45 def to_s resultado = "[ " for i in 0...@m do for j in 0...@n do resultado << " #{@datos[i][j]} " end end resultado << " ]" resultado end