Class: Matrix

Inherits:
Object
  • Object
show all
Defined in:
lib/roctave/firpm.rb

Instance Method Summary collapse

Instance Method Details

#putsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/roctave/firpm.rb', line 20

def puts
	strings = Array.new(self.row_size){Array.new(self.column_size)}
	(0 ... self.row_size).each do |i|
		(0 ... self.column_size).each do |j|
			strings[i][j] = self[i, j].round(4).to_s
		end
	end
	maxstrlen = strings.flatten.collect{|s| s.length + 2}.max
	Kernel.puts
	(0 ... self.row_size).each do |i|
		if i == 0 and i == self.row_size - 1 then
			print ' ['
		elsif i == 0 then
			print ''
		elsif i == self.row_size - 1 then
			print ''
		else
			print ''
		end

		(0 ... self.column_size).each do |j|
			print strings[i][j].center(maxstrlen)
		end

		if i == 0 and i == self.row_size - 1 then
			Kernel.puts ']'
		elsif i == 0 then
			Kernel.puts ''
		elsif i == self.row_size - 1 then
			Kernel.puts ''
		else
			Kernel.puts ''
		end
	end
	Kernel.puts
end